Skip to content

Commit 86532d4

Browse files
committed
impl: show error dialog when workspace name was not provided
- the error is also displayed when the workspace with the name does not exist
1 parent 0403ee2 commit 86532d4

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

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

+27-16
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,35 @@ open class CoderProtocolHandler(
4949
val queryToken = params.token()
5050
val restClient = try {
5151
authenticate(deploymentURL, queryToken)
52-
} catch (ex: MissingArgumentException) {
53-
throw MissingArgumentException("Query parameter \"$TOKEN\" is missing", ex)
52+
} catch (ex: Exception) {
53+
context.logger.error(ex, "Query parameter \"$TOKEN\" is missing from URI $uri")
54+
context.ui.showErrorInfoPopup(
55+
IllegalStateException(
56+
humanizeConnectionError(
57+
deploymentURL.toURL(),
58+
true,
59+
ex
60+
)
61+
)
62+
)
63+
return
5464
}
5565

56-
// TODO: Show a dropdown and ask for the workspace if missing.
57-
val workspaceName =
58-
params.workspace() ?: throw MissingArgumentException("Query parameter \"$WORKSPACE\" is missing")
66+
// TODO: Show a dropdown and ask for the workspace if missing. Right now it's not possible because dialogs are quite limited
67+
val workspaceName = params.workspace()
68+
if (workspaceName.isNullOrBlank()) {
69+
context.logger.error("Query parameter \"$WORKSPACE\" is missing from URI $uri")
70+
context.ui.showErrorInfoPopup(MissingArgumentException("Can't handle URI because query parameter \"$WORKSPACE\" is missing"))
71+
return
72+
}
5973

6074
val workspaces = restClient.workspaces()
61-
val workspace =
62-
workspaces.firstOrNull {
63-
it.name == workspaceName
64-
} ?: throw IllegalArgumentException("The workspace $workspaceName does not exist")
75+
val workspace = workspaces.firstOrNull { it.name == workspaceName }
76+
if (workspace == null) {
77+
context.logger.error("There is no workspace with name $workspaceName on $deploymentURL")
78+
context.ui.showErrorInfoPopup(MissingArgumentException("Can't handle URI because workspace with name $workspaceName does not exist"))
79+
return
80+
}
6581

6682
when (workspace.latestBuild.status) {
6783
WorkspaceStatus.PENDING, WorkspaceStatus.STARTING ->
@@ -188,13 +204,8 @@ open class CoderProtocolHandler(
188204
PluginManager.pluginInfo.version,
189205
httpClient
190206
)
191-
return try {
192-
client.authenticate()
193-
client
194-
} catch (ex: Exception) {
195-
context.ui.showErrorInfoPopup(IllegalStateException(humanizeConnectionError(client.url, true, ex)))
196-
throw ex
197-
}
207+
client.authenticate()
208+
return client
198209
}
199210

200211
/**

0 commit comments

Comments
 (0)