(e)
| 983 | this[kBufferedCommandSymbol] = ''; |
| 984 | } |
| 985 | _handleError(e) { |
| 986 | debug('handle error'); |
| 987 | if (this._userErrorHandler) { |
| 988 | const state = this._userErrorHandler(e); |
| 989 | if (state !== 'ignore' && state !== 'print' && state !== 'unhandled') { |
| 990 | throw new ERR_INVALID_STATE( |
| 991 | 'External REPL error handler must return either "ignore", "print"' + |
| 992 | `, or "unhandled", but received: ${state}`); |
| 993 | } |
| 994 | if (state === 'ignore') { |
| 995 | return; |
| 996 | } |
| 997 | if (state === 'unhandled') { |
| 998 | return 'unhandled'; |
| 999 | } |
| 1000 | } |
| 1001 | let errStack = ''; |
| 1002 | |
| 1003 | if (typeof e === 'object' && e !== null) { |
| 1004 | overrideStackTrace.set(e, (error, stackFrames) => { |
| 1005 | let frames; |
| 1006 | if (typeof stackFrames === 'object') { |
| 1007 | // Search from the bottom of the call stack to |
| 1008 | // find the first frame with a null function name |
| 1009 | const idx = ArrayPrototypeFindLastIndex( |
| 1010 | stackFrames, |
| 1011 | (frame) => frame.getFunctionName() === null, |
| 1012 | ); |
| 1013 | // If found, get rid of it and everything below it |
| 1014 | frames = ArrayPrototypeSlice(stackFrames, 0, idx); |
| 1015 | } else { |
| 1016 | frames = stackFrames; |
| 1017 | } |
| 1018 | // FIXME(devsnek): this is inconsistent with the checks |
| 1019 | // that the real prepareStackTrace dispatch uses in |
| 1020 | // lib/internal/errors.js. |
| 1021 | if (typeof MainContextError.prepareStackTrace === 'function') { |
| 1022 | return MainContextError.prepareStackTrace(error, frames); |
| 1023 | } |
| 1024 | return ErrorPrepareStackTrace(error, frames); |
| 1025 | }); |
| 1026 | decorateErrorStack(e); |
| 1027 | |
| 1028 | if (isError(e)) { |
| 1029 | if (e.stack) { |
| 1030 | if (e.name === 'SyntaxError') { |
| 1031 | // Remove stack trace. |
| 1032 | e.stack = SideEffectFreeRegExpPrototypeSymbolReplace( |
| 1033 | /^\s+at\s.*\n?/gm, |
| 1034 | SideEffectFreeRegExpPrototypeSymbolReplace(/^REPL\d+:\d+\r?\n/, e.stack, ''), |
| 1035 | ''); |
| 1036 | const importErrorStr = 'Cannot use import statement outside a ' + |
| 1037 | 'module'; |
| 1038 | if (StringPrototypeIncludes(e.message, importErrorStr)) { |
| 1039 | e.message = 'Cannot use import statement inside the Node.js ' + |
| 1040 | 'REPL, alternatively use dynamic import: ' + toDynamicImport(ArrayPrototypeAt(this.lines, -1)); |
| 1041 | e.stack = SideEffectFreeRegExpPrototypeSymbolReplace( |
| 1042 | /SyntaxError:.*\n/, |
no test coverage detected