Skip to content

Commit 837abb3

Browse files
committed
fix: NPE during error reporting
The try/catch block raised NPE in the `notify` if another exception was raised after the context containing the URL was reset - so that means an error in the onConnect handler. In addition, some of the reset steps were moved after onConnect to make sure they execute only if onConnect callback is successful. Because of the fault in how the steps were arranged, the original exception was never logged instead a misleading NPE was treated by the coroutine's exception handler.
1 parent 22f53f6 commit 837abb3

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- improved diagnose support
88

9+
### Fixed
10+
11+
- NPE during error reporting
12+
913
## 0.6.3 - 2025-08-25
1014

1115
### Added

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ class CoderRemoteProvider(
409409
context.logger.info("Displaying ${client.url} in the UI")
410410
pollJob = poll(client, cli)
411411
context.logger.info("Workspace poll job created with reference $pollJob")
412-
context.envPageManager.showPluginEnvironmentsPage()
413412
}
414413

415414
private fun MutableStateFlow<LoadableState<List<CoderRemoteEnvironment>>>.showLoadingMessage() {

src/main/kotlin/com/coder/toolbox/views/ConnectStep.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class ConnectStep(
7373
errorField.textState.update { context.i18n.ptrl("Token is required") }
7474
return
7575
}
76+
// Capture the host name early for error reporting
77+
val hostName = CoderCliSetupContext.url!!.host
78+
7679
signInJob?.cancel()
7780
signInJob = context.cs.launch(CoroutineName("Http and CLI Setup")) {
7881
try {
@@ -100,21 +103,23 @@ class ConnectStep(
100103
yield()
101104
cli.login(client.token!!)
102105
}
103-
logAndReportProgress("Successfully configured ${CoderCliSetupContext.url!!.host}...")
106+
logAndReportProgress("Successfully configured ${hostName}...")
104107
// allows interleaving with the back/cancel action
105108
yield()
106-
CoderCliSetupContext.reset()
107-
CoderCliSetupWizardState.goToFirstStep()
108109
context.logger.info("Connection setup done, initializing the workspace poller...")
109110
onConnect(client, cli)
111+
112+
CoderCliSetupContext.reset()
113+
CoderCliSetupWizardState.goToFirstStep()
114+
context.envPageManager.showPluginEnvironmentsPage()
110115
} catch (ex: CancellationException) {
111116
if (ex.message != USER_HIT_THE_BACK_BUTTON) {
112-
notify("Connection to ${CoderCliSetupContext.url!!.host} was configured", ex)
117+
notify("Connection to $hostName was configured", ex)
113118
handleNavigation()
114119
refreshWizard()
115120
}
116121
} catch (ex: Exception) {
117-
notify("Failed to configure ${CoderCliSetupContext.url!!.host}", ex)
122+
notify("Failed to configure $hostName", ex)
118123
handleNavigation()
119124
refreshWizard()
120125
}

0 commit comments

Comments
 (0)