-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the decorateErrorStack() method. This function uses the internal util's getHiddenValue() method to extract arrow messages from error objects and attach them to the error's stack trace. PR-URL: #4013 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const util = require('util'); | ||
|
||
assert.doesNotThrow(function() { | ||
util.decorateErrorStack(); | ||
util.decorateErrorStack(null); | ||
util.decorateErrorStack(1); | ||
util.decorateErrorStack(true); | ||
}); | ||
|
||
// Verify that a stack property is not added to non-Errors | ||
const obj = {}; | ||
util.decorateErrorStack(obj); | ||
assert.strictEqual(obj.stack, undefined); | ||
|
||
// Verify that the stack is decorated when possible | ||
let err; | ||
|
||
try { | ||
require('../fixtures/syntax/bad_syntax'); | ||
} catch (e) { | ||
err = e; | ||
assert(!/var foo bar;/.test(err.stack)); | ||
util.decorateErrorStack(err); | ||
} | ||
|
||
assert(/var foo bar;/.test(err.stack)); | ||
|
||
// Verify that the stack is unchanged when there is no arrow message | ||
err = new Error('foo'); | ||
const originalStack = err.stack; | ||
util.decorateErrorStack(err); | ||
assert.strictEqual(originalStack, err.stack); |