Skip to content

Commit e6e02d5

Browse files
committed
Check for the statuses we want
Instead of ones we do not. This catches unexpected statuses like how right now if there is a redirect Axios will make a GET to the new location and the workspace status becomes undefined because it got an array of builds back instead.
1 parent 214b1a1 commit e6e02d5

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/remote.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,14 @@ export class Remote {
270270
buildComplete()
271271
}
272272

273-
if (workspace.latest_build.status === "stopped") {
273+
// The workspace should now be running, but it could be stopped if the user
274+
// stopped the workspace while connected.
275+
if (workspace.latest_build.status !== "running") {
274276
const result = await this.vscodeProposed.window.showInformationMessage(
275-
`This workspace is stopped!`,
277+
`${workspaceName} is ${workspace.latest_build.status}`,
276278
{
277279
modal: true,
278-
detail: `Click below to start and open ${workspaceName}.`,
280+
detail: `Click below to start the workspace and reconnect.`,
279281
useCustom: true,
280282
},
281283
"Start Workspace",
@@ -499,16 +501,17 @@ export class Remote {
499501
this.storage.writeToCoderOutputChannel(`Agent ${agent.name} status is now ${agent.status}`)
500502
}
501503

502-
// Make sure agent did not time out.
503-
// TODO: Seems like maybe we should check for all the good states rather
504-
// than one bad state? Agents can error in many ways.
505-
if (agent.status === "timeout") {
506-
this.storage.writeToCoderOutputChannel(`${workspaceName}/${agent.name} timed out`)
507-
const result = await this.vscodeProposed.window.showErrorMessage("Connection timed out...", {
508-
useCustom: true,
509-
modal: true,
510-
detail: `The ${agent.name} agent didn't connect in time. Try restarting your workspace.`,
511-
})
504+
// Make sure the agent is connected.
505+
// TODO: Should account for the lifecycle state as well?
506+
if (agent.status !== "connected") {
507+
const result = await this.vscodeProposed.window.showErrorMessage(
508+
`${workspaceName}/${agent.name} ${agent.status}`,
509+
{
510+
useCustom: true,
511+
modal: true,
512+
detail: `The ${agent.name} agent failed to connect. Try restarting your workspace.`,
513+
},
514+
)
512515
if (!result) {
513516
await this.closeRemote()
514517
return

0 commit comments

Comments
 (0)