errors.mjs
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
17 hours ago
| 1 | /** |
| 2 | * CLI error handling: exit 1 (usage) / 2 (runtime), optional JSON error object. SPEC §4.2, §4.3. |
| 3 | */ |
| 4 | |
| 5 | /** |
| 6 | * Print error and exit. With useJson, writes { "error": message, "code": code } to stderr and exits. |
| 7 | * @param {string} message |
| 8 | * @param {1|2} code - 1 = usage, 2 = runtime |
| 9 | * @param {boolean} useJson - If true, output JSON error object to stderr |
| 10 | */ |
| 11 | export function exitWithError(message, code = 1, useJson = false) { |
| 12 | if (useJson) { |
| 13 | const err = { error: message, code: code === 1 ? 'USAGE_ERROR' : 'RUNTIME_ERROR' }; |
| 14 | process.stderr.write(JSON.stringify(err) + '\n'); |
| 15 | } else { |
| 16 | console.error(message); |
| 17 | } |
| 18 | process.exit(code); |
| 19 | } |
File History
1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
17 hours ago