* Emits an error message in the correct format based on outputFormat. * When using stream-json, writes JSON to stdout; otherwise writes plain text to stderr.
( message: string, outputFormat: string | undefined, )
| 4839 | * When using stream-json, writes JSON to stdout; otherwise writes plain text to stderr. |
| 4840 | */ |
| 4841 | function emitLoadError( |
| 4842 | message: string, |
| 4843 | outputFormat: string | undefined, |
| 4844 | ): void { |
| 4845 | if (outputFormat === 'stream-json') { |
| 4846 | const errorResult = { |
| 4847 | type: 'result', |
| 4848 | subtype: 'error_during_execution', |
| 4849 | duration_ms: 0, |
| 4850 | duration_api_ms: 0, |
| 4851 | is_error: true, |
| 4852 | num_turns: 0, |
| 4853 | stop_reason: null, |
| 4854 | session_id: getSessionId(), |
| 4855 | total_cost_usd: 0, |
| 4856 | usage: EMPTY_USAGE, |
| 4857 | modelUsage: {}, |
| 4858 | permission_denials: [], |
| 4859 | uuid: randomUUID(), |
| 4860 | errors: [message], |
| 4861 | } |
| 4862 | process.stdout.write(jsonStringify(errorResult) + '\n') |
| 4863 | } else { |
| 4864 | process.stderr.write(message + '\n') |
| 4865 | } |
| 4866 | } |
| 4867 | |
| 4868 | /** |
| 4869 | * Removes an interrupted user message and its synthetic assistant sentinel |
no test coverage detected