-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: improve error output #22436
Closed
Closed
repl: improve error output #22436
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,11 +339,6 @@ function REPLServer(prompt, | |
} catch (e) { | ||
err = e; | ||
|
||
if (err && err.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED') { | ||
// The stack trace for this case is not very useful anyway. | ||
Object.defineProperty(err, 'stack', { value: '' }); | ||
} | ||
|
||
if (process.domain) { | ||
debug('not recoverable, send to domain'); | ||
process.domain.emit('error', err); | ||
|
@@ -359,7 +354,11 @@ function REPLServer(prompt, | |
if (self.breakEvalOnSigint) { | ||
const interrupt = new Promise((resolve, reject) => { | ||
sigintListener = () => { | ||
reject(new ERR_SCRIPT_EXECUTION_INTERRUPTED()); | ||
const tmp = Error.stackTraceLimit; | ||
Error.stackTraceLimit = 0; | ||
const err = new ERR_SCRIPT_EXECUTION_INTERRUPTED(); | ||
Error.stackTraceLimit = tmp; | ||
reject(err); | ||
}; | ||
prioritizedSigintQueue.add(sigintListener); | ||
}); | ||
|
@@ -378,11 +377,6 @@ function REPLServer(prompt, | |
// Remove prioritized SIGINT listener if it was not called. | ||
prioritizedSigintQueue.delete(sigintListener); | ||
|
||
if (err.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED') { | ||
// The stack trace for this case is not very useful anyway. | ||
Object.defineProperty(err, 'stack', { value: '' }); | ||
} | ||
|
||
unpause(); | ||
if (err && process.domain) { | ||
debug('not recoverable, send to domain'); | ||
|
@@ -404,29 +398,50 @@ function REPLServer(prompt, | |
|
||
self._domain.on('error', function debugDomainError(e) { | ||
debug('domain error'); | ||
const top = replMap.get(self); | ||
const pstrace = Error.prepareStackTrace; | ||
Error.prepareStackTrace = prepareStackTrace(pstrace); | ||
if (typeof e === 'object') | ||
let errStack = ''; | ||
|
||
if (typeof e === 'object' && e !== null) { | ||
const pstrace = Error.prepareStackTrace; | ||
Error.prepareStackTrace = prepareStackTrace(pstrace); | ||
internalUtil.decorateErrorStack(e); | ||
Error.prepareStackTrace = pstrace; | ||
const isError = internalUtil.isError(e); | ||
if (!self.underscoreErrAssigned) | ||
self.lastError = e; | ||
if (e instanceof SyntaxError && e.stack) { | ||
// remove repl:line-number and stack trace | ||
e.stack = e.stack | ||
.replace(/^repl:\d+\r?\n/, '') | ||
.replace(/^\s+at\s.*\n?/gm, ''); | ||
} else if (isError && self.replMode === exports.REPL_MODE_STRICT) { | ||
e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/, | ||
(_, pre, line) => pre + (line - 1)); | ||
Error.prepareStackTrace = pstrace; | ||
|
||
if (e.domainThrown) { | ||
delete e.domain; | ||
delete e.domainThrown; | ||
} | ||
|
||
if (internalUtil.isError(e)) { | ||
if (e.stack) { | ||
if (e instanceof SyntaxError) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error could be a syntax error from another realm (so not |
||
// Remove stack trace. | ||
e.stack = e.stack | ||
.replace(/^repl:\d+\r?\n/, '') | ||
.replace(/^\s+at\s.*\n?/gm, ''); | ||
} else if (self.replMode === exports.REPL_MODE_STRICT) { | ||
e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/, | ||
(_, pre, line) => pre + (line - 1)); | ||
} | ||
} | ||
errStack = util.inspect(e); | ||
|
||
// Remove one line error braces to keep the old style in place. | ||
if (errStack[errStack.length - 1] === ']') { | ||
errStack = errStack.slice(1, -1); | ||
} | ||
} | ||
} | ||
if (isError && e.stack) { | ||
top.outputStream.write(`${e.stack}\n`); | ||
} else { | ||
top.outputStream.write(`Thrown: ${String(e)}\n`); | ||
|
||
if (errStack === '') { | ||
errStack = `Thrown: ${util.inspect(e)}`; | ||
} | ||
|
||
if (!self.underscoreErrAssigned) { | ||
self.lastError = e; | ||
} | ||
|
||
const top = replMap.get(self); | ||
top.outputStream.write(`${errStack}\n`); | ||
top.clearBufferedCommand(); | ||
top.lines.level = []; | ||
top.displayPrompt(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
.stack
creation is deferred until the.stack
is accessed does toggling theError.stackTraceLimit
have the effect wanted here (making an empty stack)? It looks likestackTraceLimit
is reset before the lazy.stack
is generated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stack size is set on error creation time. Otherwise the test would fail as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good to know!