* 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, )
| 4873 | * When using stream-json, writes JSON to stdout; otherwise writes plain text to stderr. |
| 4874 | */ |
| 4875 | function emitLoadError( |
| 4876 | message: string, |
| 4877 | outputFormat: string | undefined, |
| 4878 | ): void { |
| 4879 | if (outputFormat === 'stream-json') { |
| 4880 | const errorResult = { |
| 4881 | type: 'result', |
| 4882 | subtype: 'error_during_execution', |
| 4883 | duration_ms: 0, |
| 4884 | duration_api_ms: 0, |
| 4885 | is_error: true, |
| 4886 | num_turns: 0, |
| 4887 | stop_reason: null, |
| 4888 | session_id: getSessionId(), |
| 4889 | total_cost_usd: 0, |
| 4890 | usage: EMPTY_USAGE, |
| 4891 | modelUsage: {}, |
| 4892 | permission_denials: [], |
| 4893 | uuid: randomUUID(), |
| 4894 | errors: [message], |
| 4895 | } |
| 4896 | process.stdout.write(jsonStringify(errorResult) + '\n') |
| 4897 | } else { |
| 4898 | process.stderr.write(message + '\n') |
| 4899 | } |
| 4900 | } |
| 4901 | |
| 4902 | /** |
| 4903 | * Removes an interrupted user message and its synthetic assistant sentinel |
no test coverage detected