Skip to content

Commit d1ebe43

Browse files
committed
fix: improve error reporting when an agent can't be resolved
- uri handling tries to automatically resolve a workspace agent. - right now an exception is raised if the agent is missing or there are multiple agents for a workspace. - instead we provide a nice human-readable error notification
1 parent a6ce4fb commit d1ebe43

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main/kotlin/com/coder/toolbox/util/CoderProtocolHandler.kt

+14-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,19 @@ open class CoderProtocolHandler(
123123
}
124124

125125
// TODO: Show a dropdown and ask for an agent if missing.
126-
val agent = getMatchingAgent(params, workspace)
126+
val agent: WorkspaceAgent
127+
try {
128+
agent = getMatchingAgent(params, workspace)
129+
} catch (e: IllegalArgumentException) {
130+
context.logger.error(e, "Can't resolve an agent for workspace $workspaceName from $deploymentURL")
131+
context.showErrorPopup(
132+
MissingArgumentException(
133+
"Can't handle URI because we can't resolve an agent for workspace $workspaceName from $deploymentURL",
134+
e
135+
)
136+
)
137+
return
138+
}
127139
val status = WorkspaceAndAgentStatus.from(workspace, agent)
128140

129141
if (!status.ready()) {
@@ -265,7 +277,7 @@ internal fun resolveRedirects(url: URL): URL {
265277
* The name is ignored if the ID is set. If neither was supplied and the
266278
* workspace has only one agent, return that. Otherwise throw an error.
267279
*
268-
* @throws [MissingArgumentException, IllegalArgumentException]
280+
* @throws [IllegalArgumentException]
269281
*/
270282
internal fun getMatchingAgent(
271283
parameters: Map<String, String?>,

0 commit comments

Comments
 (0)