MCPcopy Index your code
hub / github.com/TypeStrong/ts-node / handleError

Function handleError

src/repl.ts:268–309  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

266 // well-known errors, and invoke `callback()`
267 // TODO should evalCode API get the same error-handling benefits?
268 function handleError(error: unknown) {
269 // Don't show TLA hint if the user explicitly disabled repl top level await
270 const canLogTopLevelAwaitHint =
271 service!.options.experimentalReplAwait !== false &&
272 !service!.shouldReplAwait;
273 if (error instanceof TSError) {
274 // Support recoverable compilations using >= node 6.
275 if (Recoverable && isRecoverable(error)) {
276 callback(new Recoverable(error));
277 return;
278 } else {
279 _console.error(error);
280
281 if (
282 canLogTopLevelAwaitHint &&
283 error.diagnosticCodes.some((dC) =>
284 topLevelAwaitDiagnosticCodes.includes(dC)
285 )
286 ) {
287 _console.error(getTopLevelAwaitHint());
288 }
289 callback(null);
290 }
291 } else {
292 let _error = error as Error | undefined;
293 if (
294 canLogTopLevelAwaitHint &&
295 _error instanceof SyntaxError &&
296 _error.message?.includes('await is only valid')
297 ) {
298 try {
299 // Only way I know to make our hint appear after the error
300 _error.message += `\n\n${getTopLevelAwaitHint()}`;
301 _error.stack = _error.stack?.replace(
302 /(SyntaxError:.*)/,
303 (_, $1) => `${$1}\n\n${getTopLevelAwaitHint()}`
304 );
305 } catch {}
306 }
307 callback(_error as Error);
308 }
309 }
310 function getTopLevelAwaitHint() {
311 return `Hint: REPL top-level await requires TypeScript version 3.8 or higher and target ES2018 or higher. You are using TypeScript ${
312 service!.ts.version

Callers 1

nodeEvalFunction · 0.85

Calls 2

isRecoverableFunction · 0.85
getTopLevelAwaitHintFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…