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

refactor: remove unsafe non-null assertions to prevent race condition#205

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 intomainfromrefactor-unsafe-not-null-assertions
Oct 7, 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@@ -2,6 +2,10 @@

## Unreleased

### Fixed

- potential race condition that could cause crashes when settings are modified concurrently

## 0.7.0 - 2025-09-27

### Changed
Expand Down
18 changes: 8 additions & 10 deletionssrc/main/kotlin/com/coder/toolbox/cli/CoderCLIManager.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -354,24 +354,22 @@ class CoderCLIManager(
// always use the correct URL.
"--url",
escape(deploymentURL.toString()),
if (!context.settingsStore.headerCommand.isNullOrBlank())"--header-command"else null,
if (!context.settingsStore.headerCommand.isNullOrBlank())escapeSubcommand(context.settingsStore.headerCommand!!) else null,
context.settingsStore.headerCommand?.takeIf { it.isNotBlank() }?.let {"--header-command"},
context.settingsStore.headerCommand?.takeIf { it.isNotBlank() }?.let {escapeSubcommand(it) },
"ssh",
"--stdio",
if (context.settingsStore.disableAutostart && feats.disableAutostart) "--disable-autostart" else null,
"--network-info-dir ${escape(context.settingsStore.networkInfoDir)}"
)
val proxyArgs = baseArgs + listOfNotNull(
if (!context.settingsStore.sshLogDirectory.isNullOrBlank())"--log-dir"else null,
if (!context.settingsStore.sshLogDirectory.isNullOrBlank())escape(context.settingsStore.sshLogDirectory!!) else null,
context.settingsStore.sshLogDirectory?.takeIf { it.isNotBlank() }?.let {"--log-dir"},
context.settingsStore.sshLogDirectory?.takeIf { it.isNotBlank() }?.let {escape(it) },
if (feats.reportWorkspaceUsage) "--usage-app=jetbrains" else null,
)
val extraConfig =
if (!context.settingsStore.sshConfigOptions.isNullOrBlank()) {
"\n" + context.settingsStore.sshConfigOptions!!.prependIndent(" ")
} else {
""
}
val extraConfig = context.settingsStore.sshConfigOptions
?.takeIf { it.isNotBlank() }
?.let { "\n" + it.prependIndent(" ") }
?: ""
val options = """
ConnectTimeout 0
StrictHostKeyChecking no
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,12 +21,12 @@ object CoderHttpClientBuilder {
val trustManagers = coderTrustManagers(settings.tls.caPath)
var builder = OkHttpClient.Builder()

if (context.proxySettings.getProxy() != null) {
context.logger.info("proxy: ${context.proxySettings.getProxy()}")
builder.proxy(context.proxySettings.getProxy())
}else if (context.proxySettings.getProxySelector() != null) {
context.logger.info("proxy selector: ${context.proxySettings.getProxySelector()}")
builder.proxySelector(context.proxySettings.getProxySelector()!!)
context.proxySettings.getProxy()?.let { proxy ->
context.logger.info("proxy: $proxy")
builder.proxy(proxy)
}?:context.proxySettings.getProxySelector()?.let { proxySelector ->
context.logger.info("proxy selector: $proxySelector")
builder.proxySelector(proxySelector)
}

// Note: This handles only HTTP/HTTPS proxy authentication.
Expand Down
68 changes: 37 additions & 31 deletionssrc/main/kotlin/com/coder/toolbox/sdk/CoderRestClient.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,9 @@ import com.coder.toolbox.sdk.v2.models.CreateWorkspaceBuildRequest
import com.coder.toolbox.sdk.v2.models.Template
import com.coder.toolbox.sdk.v2.models.User
import com.coder.toolbox.sdk.v2.models.Workspace
import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
import com.coder.toolbox.sdk.v2.models.WorkspaceBuild
import com.coder.toolbox.sdk.v2.models.WorkspaceBuildReason
import com.coder.toolbox.sdk.v2.models.WorkspaceResource
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
import com.coder.toolbox.sdk.v2.models.WorkspaceTransition
import com.squareup.moshi.Moshi
import okhttp3.OkHttpClient
Expand DownExpand Up@@ -114,7 +112,9 @@ open class CoderRestClient(
)
}

return userResponse.body()!!
return requireNotNull(userResponse.body()) {
"Successful response returned null body or user"
}
}

/**
Expand All@@ -132,41 +132,29 @@ open class CoderRestClient(
)
}

return workspacesResponse.body()!!.workspaces
return requireNotNull(workspacesResponse.body()?.workspaces) {
"Successful response returned null body or workspaces"
}
}

/**
* Retrieves a workspace with the provided id.
* @throws [APIResponseException].
*/
suspend fun workspace(workspaceID: UUID): Workspace {
valworkspacesResponse = retroRestClient.workspace(workspaceID)
if (!workspacesResponse.isSuccessful) {
valworkspaceResponse = retroRestClient.workspace(workspaceID)
if (!workspaceResponse.isSuccessful) {
throw APIResponseException(
"retrieve workspace",
url,
workspacesResponse.code(),
workspacesResponse.parseErrorBody(moshi)
workspaceResponse.code(),
workspaceResponse.parseErrorBody(moshi)
)
}

return workspacesResponse.body()!!
}

/**
* Maps the available workspaces to the associated agents.
*/
suspend fun workspacesByAgents(): Set<Pair<Workspace, WorkspaceAgent>> {
// It is possible for there to be resources with duplicate names so we
// need to use a set.
return workspaces().flatMap { ws ->
when (ws.latestBuild.status) {
WorkspaceStatus.RUNNING -> ws.latestBuild.resources
else -> resources(ws)
}.filter { it.agents != null }.flatMap { it.agents!! }.map {
ws to it
}
}.toSet()
return requireNotNull(workspaceResponse.body()) {
"Successful response returned null body or workspace"
}
}

/**
Expand All@@ -187,7 +175,10 @@ open class CoderRestClient(
resourcesResponse.parseErrorBody(moshi)
)
}
return resourcesResponse.body()!!

return requireNotNull(resourcesResponse.body()) {
"Successful response returned null body or workspace resources"
}
}

suspend fun buildInfo(): BuildInfo {
Expand All@@ -200,7 +191,10 @@ open class CoderRestClient(
buildInfoResponse.parseErrorBody(moshi)
)
}
return buildInfoResponse.body()!!

return requireNotNull(buildInfoResponse.body()) {
"Successful response returned null body or build info"
}
}

/**
Expand All@@ -216,7 +210,10 @@ open class CoderRestClient(
templateResponse.parseErrorBody(moshi)
)
}
return templateResponse.body()!!

return requireNotNull(templateResponse.body()) {
"Successful response returned null body or template"
}
}

/**
Expand All@@ -238,7 +235,10 @@ open class CoderRestClient(
buildResponse.parseErrorBody(moshi)
)
}
return buildResponse.body()!!

return requireNotNull(buildResponse.body()) {
"Successful response returned null body or workspace build"
}
}

/**
Expand All@@ -254,7 +254,10 @@ open class CoderRestClient(
buildResponse.parseErrorBody(moshi)
)
}
return buildResponse.body()!!

return requireNotNull(buildResponse.body()) {
"Successful response returned null body or workspace build"
}
}

/**
Expand DownExpand Up@@ -296,7 +299,10 @@ open class CoderRestClient(
buildResponse.parseErrorBody(moshi)
)
}
return buildResponse.body()!!

return requireNotNull(buildResponse.body()) {
"Successful response returned null body or workspace build"
}
}

fun close() {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -252,7 +252,10 @@ open class CoderProtocolHandler(
parameters: Map<String, String?>,
workspace: Workspace,
): WorkspaceAgent? {
val agents = workspace.latestBuild.resources.filter { it.agents != null }.flatMap { it.agents!! }
val agents = workspace.latestBuild.resources
.mapNotNull { it.agents }
.flatten()

if (agents.isEmpty()) {
context.logAndShowError(CAN_T_HANDLE_URI_TITLE, "The workspace \"${workspace.name}\" has no agents")
return null
Expand Down
9 changes: 5 additions & 4 deletionssrc/main/kotlin/com/coder/toolbox/views/ConnectStep.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,15 +56,16 @@ class ConnectStep(
return
}

statusField.textState.update { context.i18n.pnotr("Connecting to ${CoderCliSetupContext.url!!.host}...") }
statusField.textState.update { context.i18n.pnotr("Connecting to ${CoderCliSetupContext.url?.host ?: "unknown host"}...") }
connect()
}

/**
* Try connecting to Coder with the provided URL and token.
*/
private fun connect() {
if (!CoderCliSetupContext.hasUrl()) {
val url = CoderCliSetupContext.url
if (url == null) {
errorField.textState.update { context.i18n.ptrl("URL is required") }
return
}
Expand All@@ -74,15 +75,15 @@ class ConnectStep(
return
}
// Capture the host name early for error reporting
val hostName =CoderCliSetupContext.url!!.host
val hostName = url.host

signInJob?.cancel()
signInJob = context.cs.launch(CoroutineName("Http and CLI Setup")) {
try {
context.logger.info("Setting up the HTTP client...")
val client = CoderRestClient(
context,
CoderCliSetupContext.url!!,
url,
if (context.settingsStore.requireTokenAuth) CoderCliSetupContext.token else null,
PluginManager.pluginInfo.version,
)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp