Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0df8c59

Browse files
committed
fix: rework the exception handler for the connection step
Calling onBack() in the exception handler doesn't make sense because: - the coroutine is already interrupted by the exception - onBack() is meant to handle user-initiated back navigation, not error recovery - we still want the proper navigation logic but without the coroutine cancellation part
1 parent 5f73723 commit 0df8c59

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ class ConnectStep(
110110
} catch (ex: CancellationException) {
111111
if (ex.message != USER_HIT_THE_BACK_BUTTON) {
112112
notify("Connection to ${CoderCliSetupContext.url!!.host} was configured", ex)
113-
onBack()
113+
handleNavigation()
114114
refreshWizard()
115115
}
116116
} catch (ex: Exception) {
117117
notify("Failed to configure ${CoderCliSetupContext.url!!.host}", ex)
118-
onBack()
118+
handleNavigation()
119119
refreshWizard()
120120
}
121121
}
@@ -126,6 +126,26 @@ class ConnectStep(
126126
statusField.textState.update { context.i18n.pnotr(msg) }
127127
}
128128

129+
/**
130+
* Handle navigation logic for both errors and back button
131+
*/
132+
private fun handleNavigation() {
133+
if (shouldAutoLogin.value) {
134+
CoderCliSetupContext.reset()
135+
if (jumpToMainPageOnError) {
136+
context.popupPluginMainPage()
137+
} else {
138+
CoderCliSetupWizardState.goToFirstStep()
139+
}
140+
} else {
141+
if (context.settingsStore.requireTokenAuth) {
142+
CoderCliSetupWizardState.goToPreviousStep()
143+
} else {
144+
CoderCliSetupWizardState.goToFirstStep()
145+
}
146+
}
147+
}
148+
129149
override fun onNext(): Boolean {
130150
return false
131151
}
@@ -135,20 +155,7 @@ class ConnectStep(
135155
context.logger.info("Back button was pressed, cancelling in-progress connection setup...")
136156
signInJob?.cancel(CancellationException(USER_HIT_THE_BACK_BUTTON))
137157
} finally {
138-
if (shouldAutoLogin.value) {
139-
CoderCliSetupContext.reset()
140-
if (jumpToMainPageOnError) {
141-
context.popupPluginMainPage()
142-
} else {
143-
CoderCliSetupWizardState.goToFirstStep()
144-
}
145-
} else {
146-
if (context.settingsStore.requireTokenAuth) {
147-
CoderCliSetupWizardState.goToPreviousStep()
148-
} else {
149-
CoderCliSetupWizardState.goToFirstStep()
150-
}
151-
}
158+
handleNavigation()
152159
}
153160
}
154161
}

0 commit comments

Comments
 (0)