Skip to content

Commit 8cdbd3a

Browse files
committed
Include stderr and full command in workspace start error message
1 parent cdccb52 commit 8cdbd3a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/api.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ export async function startWorkspaceIfStoppedOrFailed(
137137
}
138138

139139
return new Promise((resolve, reject) => {
140-
const startProcess = spawn(binPath, ["start", "--yes", workspace.owner_name + "/" + workspace.name])
140+
const startArgs = ["start", "--yes", workspace.owner_name + "/" + workspace.name]
141+
const startProcess = spawn(binPath, startArgs)
141142

142143
startProcess.stdout.on("data", (data: Buffer) => {
143144
data
@@ -150,13 +151,15 @@ export async function startWorkspaceIfStoppedOrFailed(
150151
})
151152
})
152153

154+
let capturedStderr = ""
153155
startProcess.stderr.on("data", (data: Buffer) => {
154156
data
155157
.toString()
156158
.split(/\r*\n/)
157159
.forEach((line: string) => {
158160
if (line !== "") {
159161
writeEmitter.fire(line.toString() + "\r\n")
162+
capturedStderr += line.toString() + "\n"
160163
}
161164
})
162165
})
@@ -165,7 +168,11 @@ export async function startWorkspaceIfStoppedOrFailed(
165168
if (code === 0) {
166169
resolve(restClient.getWorkspace(workspace.id))
167170
} else {
168-
reject(new Error(`"coder start" process exited with code ${code}`))
171+
let errorText = `"${startArgs.join(" ")}" exited with code ${code}`
172+
if (capturedStderr !== "") {
173+
errorText += `: ${capturedStderr}`
174+
}
175+
reject(new Error(errorText))
169176
}
170177
})
171178
})

0 commit comments

Comments
 (0)