Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc24b7d

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 theautologin screen.- the autologin screen will display an error and stop the authenticationif errors are encountered.
1 parentdb3ea7d commitfc24b7d

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
importcom.coder.toolbox.cli.CoderCLIManager
44
importcom.coder.toolbox.sdk.CoderRestClient
5-
importcom.coder.toolbox.sdk.ex.APIResponseException
65
importcom.coder.toolbox.sdk.v2.models.WorkspaceStatus
76
importcom.coder.toolbox.util.CoderProtocolHandler
87
importcom.coder.toolbox.util.DialogUi
@@ -30,7 +29,6 @@ import kotlinx.coroutines.isActive
3029
importkotlinx.coroutines.launch
3130
importkotlinx.coroutines.selects.onTimeout
3231
importkotlinx.coroutines.selects.select
33-
importjava.net.SocketTimeoutException
3432
importjava.net.URI
3533
importkotlin.coroutines.cancellation.CancellationException
3634
importkotlin.time.Duration.Companion.seconds
@@ -58,11 +56,6 @@ class CoderRemoteProvider(
5856
// The REST client, if we are signed in
5957
privatevar 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-
privatevar errorBuffer= mutableListOf<Throwable>()
65-
6659
// On the first load, automatically log in if we can.
6760
privatevar firstRun=true
6861
privateval 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
overridefungetOverrideUiPage():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
returnnull
@@ -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)

[8]ページ先頭

©2009-2025 Movatter.jp