MCPcopy Index your code
hub / github.com/coder/mux / sanitizeCoderCliErrorForUi

Function sanitizeCoderCliErrorForUi

src/node/services/coderService.ts:288–316  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

286}
287
288function sanitizeCoderCliErrorForUi(error: unknown): string {
289 if (!(error instanceof Error)) {
290 return "Unknown error";
291 }
292
293 const err = error as Partial<{ stderr: string; message: string }>;
294 const raw = (err.stderr?.trim() ? err.stderr : err.message) ?? "";
295
296 const lines = raw
297 .split(/\r?\n/)
298 .map((line) => line.trim())
299 .filter(Boolean);
300
301 if (lines.length === 0) {
302 return "Unknown error";
303 }
304
305 // Coder often prints a generic "Encountered an error running..." line followed by
306 // a more actionable "error: ..." line. Prefer the latter when present.
307 const preferred =
308 [...lines].reverse().find((line) => /^error:\s*/i.test(line)) ?? lines[lines.length - 1];
309
310 return (
311 preferred
312 .replace(/^error:\s*/i, "")
313 .slice(0, 200)
314 .trim() || "Unknown error"
315 );
316}
317
318export class CoderService {
319 // Ephemeral API sessions scoped to workspace provisioning.

Callers 4

classifyCoderErrorMethod · 0.85
listTemplatesMethod · 0.85
listPresetsMethod · 0.85
listWorkspacesMethod · 0.85

Calls 1

testMethod · 0.80

Tested by

no test coverage detected