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

fix: simplify and improve error handling during workspace polling#86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fioan89 merged 1 commit intomainfromimproved-polling-error-handling
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,10 @@

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

### Changed

- improved error handling during workspace polling

## 0.1.4 - 2025-04-11

### Fixed
Expand Down
30 changes: 5 additions & 25 deletionssrc/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,6 @@ package com.coder.toolbox

import com.coder.toolbox.cli.CoderCLIManager
import com.coder.toolbox.sdk.CoderRestClient
import com.coder.toolbox.sdk.ex.APIResponseException
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
import com.coder.toolbox.util.CoderProtocolHandler
import com.coder.toolbox.util.DialogUi
Expand DownExpand Up@@ -30,7 +29,6 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.selects.onTimeout
import kotlinx.coroutines.selects.select
import java.net.SocketTimeoutException
import java.net.URI
import kotlin.coroutines.cancellation.CancellationException
import kotlin.time.Duration.Companion.seconds
Expand DownExpand Up@@ -58,11 +56,6 @@ class CoderRemoteProvider(
// The REST client, if we are signed in
private var client: CoderRestClient? = null

// If we have an error in the polling we store it here before going back to
// sign-in page, so we can display it there. This is mainly because there
// does not seem to be a mechanism to show errors on the environment list.
private var errorBuffer = mutableListOf<Throwable>()

// On the first load, automatically log in if we can.
private var firstRun = true
private val isInitialized: MutableStateFlow<Boolean> = MutableStateFlow(false)
Expand DownExpand Up@@ -135,29 +128,17 @@ class CoderRemoteProvider(
} catch (_: CancellationException) {
context.logger.debug("${client.url} polling loop canceled")
break
} catch (ex:SocketTimeoutException) {
} catch (ex:Exception) {
val elapsed = lastPollTime.elapsedNow()
if (elapsed > POLL_INTERVAL * 2) {
context.logger.info("wake-up from an OS sleep was detected, going to re-initialize the http client...")
client.setupSession()
} else {
context.logger.error(ex, "workspace polling error encountered")
errorBuffer.add(ex)
logout()
context.logger.error(ex, "workspace polling error encountered, trying to auto-login")
close()
goToEnvironmentsPage()
break
}
} catch (ex: APIResponseException) {
context.logger.error(ex, "error in contacting ${client.url} while polling the available workspaces")
errorBuffer.add(ex)
logout()
goToEnvironmentsPage()
break
} catch (ex: Exception) {
context.logger.error(ex, "workspace polling error encountered")
errorBuffer.add(ex)
logout()
goToEnvironmentsPage()
break
}

// TODO: Listening on a web socket might be better?
Expand DownExpand Up@@ -306,6 +287,7 @@ class CoderRemoteProvider(
override fun getOverrideUiPage(): UiPage? {
// Show sign in page if we have not configured the client yet.
if (client == null) {
val errorBuffer = mutableListOf<Throwable>()
// When coming back to the application, authenticate immediately.
val autologin = shouldDoAutoLogin()
context.secrets.lastToken.let { lastToken ->
Expand All@@ -329,7 +311,6 @@ class CoderRemoteProvider(
authWizard.notify("Error encountered", it)
}
// and now reset the errors, otherwise we show it every time on the screen
errorBuffer.clear()
return authWizard
}
return null
Expand All@@ -344,7 +325,6 @@ class CoderRemoteProvider(
// Currently we always remember, but this could be made an option.
context.secrets.rememberMe = true
this.client = client
errorBuffer.clear()
pollJob?.cancel()
pollJob = poll(client, cli)
goToEnvironmentsPage()
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp