MCPcopy Create free account
hub / github.com/apache/maka / normalizeQuickJsError

Function normalizeQuickJsError

packages/code-mode/src/quickjs.ts:112–157  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

110}
111
112function normalizeQuickJsError(error: unknown): CodeModeDiagnostic {
113 const message = error instanceof Error ? error.message : String(error);
114 const isRunError =
115 error instanceof Error && (error as Error & { code?: unknown }).code === 'RUN_ERROR';
116 const isSourceSyntaxRunError =
117 isRunError &&
118 error.name === 'SyntaxError' &&
119 /\n\s+at code-mode\.js:\d+:\d+\s*$/.test(error.stack ?? '');
120 if (error instanceof SyntaxError || isSourceSyntaxRunError) {
121 return { kind: 'parse_error', message };
122 }
123 if (
124 isRunError &&
125 error.name === 'InternalError' &&
126 (/^interrupted$/i.test(message) || /out of memory|stack (?:size|overflow)/i.test(message))
127 ) {
128 return { kind: 'limit_exceeded', message };
129 }
130 if (error instanceof CodeModeError) {
131 if (
132 error.code === 'CODE_MODE_TIMEOUT' ||
133 error.code === 'CODE_MODE_CONCURRENCY_LIMIT' ||
134 error.code === 'CODE_MODE_SOURCE_TOO_LARGE' ||
135 error.code === 'CODE_MODE_BRIDGE_LIMIT'
136 ) {
137 return { kind: 'limit_exceeded', message };
138 }
139 if (error.code === 'CODE_MODE_SERIALIZATION_ERROR') {
140 return {
141 kind: /exceeds? the \d+ byte size limit/i.test(message) ? 'limit_exceeded' : 'tool_failure',
142 message,
143 };
144 }
145 if (error.code === 'CODE_MODE_TOOL_ERROR' && /^Unknown tool:/i.test(message)) {
146 return { kind: 'unknown_tool', message };
147 }
148 if (error.code === 'CODE_MODE_TOOL_ERROR') return { kind: 'tool_failure', message };
149 if (
150 error.name === 'InternalError' &&
151 (/^interrupted$/i.test(message) || /out of memory|stack (?:size|overflow)/i.test(message))
152 ) {
153 return { kind: 'limit_exceeded', message };
154 }
155 }
156 return { kind: 'execution_error', message };
157}

Callers 1

executeCodeCellImplFunction · 0.85

Calls 1

testMethod · 0.65

Tested by

no test coverage detected