Closed lidongjies closed 4 years ago
A stack trace:
$ node
Welcome to Node.js v12.13.0.
Type ".help" for more information.
> console.log((new Error).stack)
Error
at repl:1:14
at Script.runInThisContext (vm.js:116:20)
at REPLServer.defaultEval (repl.js:404:29)
at bound (domain.js:420:14)
at REPLServer.runBound [as eval] (domain.js:433:12)
at REPLServer.onLine (repl.js:715:10)
at REPLServer.emit (events.js:215:7)
at REPLServer.EventEmitter.emit (domain.js:476:20)
at REPLServer.Interface._onLine (readline.js:316:10)
at REPLServer.Interface._line (readline.js:693:8)
undefined
>
The same stack trace if bound
was marked as "sensitive"
:
$ node
Welcome to Node.js v12.13.0.
Type ".help" for more information.
> console.log((new Error).stack)
Error
at repl:1:14
at Script.runInThisContext (vm.js:116:20)
at REPLServer.defaultEval (repl.js:404:29)
at REPLServer.runBound [as eval] (domain.js:433:12)
at REPLServer.onLine (repl.js:715:10)
at REPLServer.emit (events.js:215:7)
at REPLServer.EventEmitter.emit (domain.js:476:20)
at REPLServer.Interface._onLine (readline.js:316:10)
at REPLServer.Interface._line (readline.js:693:8)
undefined
>
The same stack trace if bound
was marked as "hide source"
:
$ node
Welcome to Node.js v12.13.0.
Type ".help" for more information.
> console.log((new Error).stack)
Error
at repl:1:14
at Script.runInThisContext (vm.js:116:20)
at REPLServer.defaultEval (repl.js:404:29)
at anonymous
at REPLServer.runBound [as eval] (domain.js:433:12)
at REPLServer.onLine (repl.js:715:10)
at REPLServer.emit (events.js:215:7)
at REPLServer.EventEmitter.emit (domain.js:476:20)
at REPLServer.Interface._onLine (readline.js:316:10)
at REPLServer.Interface._line (readline.js:693:8)
undefined
>
@michaelficarra Can we add this example to README? It will be very helpful for the developers to understand the behavior.
@hax done, thanks for the suggestion.
why use anonymous
instead of the function name? As I know Error.prototype.stack
is non-standard though de facto.
try {
;[1, 2, 3].forEach(i => {
if (i > 1) {
throw new Error()
}
})
} catch (e) {
console.log('%s', e.stack)
}
Chrome
Error at file:///Users/makeco/Github/function-implementation-hiding/index.js:4:10 at Array.forEach (\<anonymous>) at file:///Users/makeco/Github/function-implementation-hiding/index.js:2:13
Safari
safari file:///Users/makeco/Github/function-implementation-hiding/index.js:4:19 forEach@[native code] global code@file:///Users/makeco/Github/function-implementation-hiding/index.js:2:20
Firefox
firefox @file:///Users/makeco/Github/function-implementation-hiding/index.js:4:10 @file:///Users/makeco/Github/function-implementation-hiding/index.js:2:13
@makeco Sorry, this was my error. The name will still appear in the stack trace, but file/position information will not. So the correct example for "hide source"
would be something like
$ node
Welcome to Node.js v12.13.0.
Type ".help" for more information.
> console.log((new Error).stack)
Error
at repl:1:14
at Script.runInThisContext (vm.js:116:20)
at REPLServer.defaultEval (repl.js:404:29)
at bound (<anonymous>)
at REPLServer.runBound [as eval] (domain.js:433:12)
at REPLServer.onLine (repl.js:715:10)
at REPLServer.emit (events.js:215:7)
at REPLServer.EventEmitter.emit (domain.js:476:20)
at REPLServer.Interface._onLine (readline.js:316:10)
at REPLServer.Interface._line (readline.js:693:8)
undefined
>
matching the output for built-in functions. I will update the example in the README to match.
I don't know clearly the difference between
hide source
andsensitive
apply onError.prototype.stack
.