Skip to content

Commit fc24b7d

Browse files
authored
fix: simplify and improve error handling during workspace polling (#86)
- detect if there is an os wake-up for all types of errors - if there is an os wake-up we try to re-init the http client. - if that doesn't work out, the polling stops and redirects to the autologin screen. - the autologin screen will display an error and stop the authentication if errors are encountered.
1 parent db3ea7d commit fc24b7d

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

CHANGELOG.md

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

77
- login screen is shown instead of an empty list of workspaces when token expired
88

9+
### Changed
10+
11+
- improved error handling during workspace polling
12+
913
## 0.1.4 - 2025-04-11
1014

1115
### Fixed

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

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.coder.toolbox
22

33
import com.coder.toolbox.cli.CoderCLIManager
44
import com.coder.toolbox.sdk.CoderRestClient
5-
import com.coder.toolbox.sdk.ex.APIResponseException
65
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
76
import com.coder.toolbox.util.CoderProtocolHandler
87
import com.coder.toolbox.util.DialogUi
@@ -30,7 +29,6 @@ import kotlinx.coroutines.isActive
3029
import kotlinx.coroutines.launch
3130
import kotlinx.coroutines.selects.onTimeout
3231
import kotlinx.coroutines.selects.select
33-
import java.net.SocketTimeoutException
3432
import java.net.URI
3533
import kotlin.coroutines.cancellation.CancellationException
3634
import kotlin.time.Duration.Companion.seconds
@@ -58,11 +56,6 @@ class CoderRemoteProvider(
5856
// The REST client, if we are signed in
5957
private var client: CoderRestClient? = null
6058

61-
// If we have an error in the polling we store it here before going back to
62-
// sign-in page, so we can display it there. This is mainly because there
63-
// does not seem to be a mechanism to show errors on the environment list.
64-
private var errorBuffer = mutableListOf<Throwable>()
65-
6659
// On the first load, automatically log in if we can.
6760
private var firstRun = true
6861
private val isInitialized: MutableStateFlow<Boolean> = MutableStateFlow(false)
@@ -135,29 +128,17 @@ class CoderRemoteProvider(
135128
} catch (_: CancellationException) {
136129
context.logger.debug("${client.url} polling loop canceled")
137130
break
138-
} catch (ex: SocketTimeoutException) {
131+
} catch (ex: Exception) {
139132
val elapsed = lastPollTime.elapsedNow()
140133
if (elapsed > POLL_INTERVAL * 2) {
141134
context.logger.info("wake-up from an OS sleep was detected, going to re-initialize the http client...")
142135
client.setupSession()
143136
} else {
144-
context.logger.error(ex, "workspace polling error encountered")
145-
errorBuffer.add(ex)
146-
logout()
137+
context.logger.error(ex, "workspace polling error encountered, trying to auto-login")
138+
close()
139+
goToEnvironmentsPage()
147140
break
148141
}
149-
} catch (ex: APIResponseException) {
150-
context.logger.error(ex, "error in contacting ${client.url} while polling the available workspaces")
151-
errorBuffer.add(ex)
152-
logout()
153-
goToEnvironmentsPage()
154-
break
155-
} catch (ex: Exception) {
156-
context.logger.error(ex, "workspace polling error encountered")
157-
errorBuffer.add(ex)
158-
logout()
159-
goToEnvironmentsPage()
160-
break
161142
}
162143

163144
// TODO: Listening on a web socket might be better?
@@ -306,6 +287,7 @@ class CoderRemoteProvider(
306287
override fun getOverrideUiPage(): UiPage? {
307288
// Show sign in page if we have not configured the client yet.
308289
if (client == null) {
290+
val errorBuffer = mutableListOf<Throwable>()
309291
// When coming back to the application, authenticate immediately.
310292
val autologin = shouldDoAutoLogin()
311293
context.secrets.lastToken.let { lastToken ->
@@ -329,7 +311,6 @@ class CoderRemoteProvider(
329311
authWizard.notify("Error encountered", it)
330312
}
331313
// and now reset the errors, otherwise we show it every time on the screen
332-
errorBuffer.clear()
333314
return authWizard
334315
}
335316
return null
@@ -344,7 +325,6 @@ class CoderRemoteProvider(
344325
// Currently we always remember, but this could be made an option.
345326
context.secrets.rememberMe = true
346327
this.client = client
347-
errorBuffer.clear()
348328
pollJob?.cancel()
349329
pollJob = poll(client, cli)
350330
goToEnvironmentsPage()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy