Skip to content

Commit 582b789

Browse files
committed
Fix: show working workspaces
- finer grained error handling when resolving agents - resolves #51
1 parent ea13402 commit 582b789

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## [Unreleased]
66
### Fixed
77
- `Recent Coder Workspaces` label overlaps with the search bar in the `Connections` view
8+
- working Workspaces are now listed when there are issues with resolving agents
89

910
### Changed
1011
- links to documentation now point to the latest Coder OSS

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.coder.gateway.sdk.Arch
88
import com.coder.gateway.sdk.CoderRestClientService
99
import com.coder.gateway.sdk.OS
1010
import com.coder.gateway.sdk.v2.models.ProvisionerJobStatus
11+
import com.coder.gateway.sdk.v2.models.Workspace
1112
import com.coder.gateway.sdk.v2.models.WorkspaceBuildTransition
1213
import com.intellij.ide.IdeBundle
1314
import com.intellij.openapi.Disposable
@@ -87,23 +88,7 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
8788
cs.launch {
8889
val workspaceList = withContext(Dispatchers.IO) {
8990
try {
90-
val workspaces = coderClient.workspaces()
91-
return@withContext workspaces.flatMap { workspace ->
92-
val agents = coderClient.workspaceAgents(workspace)
93-
val shouldContainAgentName = agents.size > 1
94-
agents.map { agent ->
95-
val workspaceName = if (shouldContainAgentName) "${workspace.name}.${agent.name}" else workspace.name
96-
WorkspaceAgentModel(
97-
workspaceName,
98-
workspace.templateName,
99-
workspace.latestBuild.job.status,
100-
workspace.latestBuild.workspaceTransition,
101-
OS.from(agent.operatingSystem),
102-
Arch.from(agent.architecture),
103-
agent.directory
104-
)
105-
}
106-
}
91+
return@withContext coderClient.workspaces().collectAgents()
10792
} catch (e: Exception) {
10893
logger.error("Could not retrieve workspaces for ${coderClient.me.username} on ${coderClient.coderURL}. Reason: $e")
10994
emptyList()
@@ -115,6 +100,30 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
115100
}
116101
}
117102

103+
private fun List<Workspace>.collectAgents(): List<WorkspaceAgentModel> {
104+
return this.flatMap { workspace ->
105+
try {
106+
val agents = coderClient.workspaceAgents(workspace)
107+
val shouldContainAgentName = agents.size > 1
108+
return@flatMap agents.map { agent ->
109+
val workspaceName = if (shouldContainAgentName) "${workspace.name}.${agent.name}" else workspace.name
110+
WorkspaceAgentModel(
111+
workspaceName,
112+
workspace.templateName,
113+
workspace.latestBuild.job.status,
114+
workspace.latestBuild.workspaceTransition,
115+
OS.from(agent.operatingSystem),
116+
Arch.from(agent.architecture),
117+
agent.directory
118+
)
119+
}
120+
} catch (e: Exception) {
121+
logger.error("Skipping workspace ${workspace.name} because we could not retrieve the agent(s). Reason: $e")
122+
emptyList()
123+
}
124+
}
125+
}
126+
118127
override fun onNext(wizardModel: CoderWorkspacesWizardModel): Boolean {
119128
val workspace = tableOfWorkspaces.selectedObject
120129
if (workspace != null) {

0 commit comments

Comments
 (0)