MCPcopy
hub / github.com/Fission-AI/OpenSpec / failWithError

Function failWithError

src/cli/index.ts:56–80  ·  view source on GitHub ↗
(
  error: unknown,
  json?: { enabled: boolean | undefined; payload?: Record<string, unknown>; fallbackCode?: string }
)

Source from the content-addressed store, hash-verified

54}
55
56function failWithError(
57 error: unknown,
58 json?: { enabled: boolean | undefined; payload?: Record<string, unknown>; fallbackCode?: string }
59): void {
60 // The agent contract: every --json failure leaves exactly one JSON
61 // document on stdout (the command's null-shape plus a status array).
62 if (json?.enabled) {
63 console.log(
64 JSON.stringify(
65 { ...(json.payload ?? {}), status: [asStatus(error, json.fallbackCode ?? 'command_error')] },
66 null,
67 2
68 )
69 );
70 process.exitCode = 1;
71 return;
72 }
73 ora().fail(`Error: ${(error as Error).message}`);
74 // Resolution and store errors carry a pasteable fix - never drop it.
75 const fix = (error as { diagnostic?: { fix?: string } }).diagnostic?.fix;
76 if (fix) {
77 console.error(`Fix: ${fix}`);
78 }
79 process.exitCode = process.exitCode ?? 1;
80}
81
82const program = new Command();
83const require = createRequire(import.meta.url);

Callers 1

index.tsFile · 0.85

Calls 1

asStatusFunction · 0.85

Tested by

no test coverage detected