Safely ignore error stack trace
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 399
- Forks
- 11
- Avg merge
- 29m
- Merged PRs (30d)
- 1
Description
I saw this library https://github.com/isaacs/catcher and I decided to wrote a benchmark:
Doing some changes on bench/error.js, the result was:
| name | ops/sec | samples |
|---|---|---|
| Error | 337,720 | 64 |
| Error (stackTraceLimit=0) | 3,284,296 | 94 |
| NodeError | 283,026 | 99 |
| NodeError (stackTraceLimit=0) | 3,280,933 | 95 |
| NodeError Range | 214,825 | 92 |
| NodeError Range (stackTraceLimit=0) | 3,313,990 | 99 |
Code
const { createBenchmarkSuite } = require('../common')
const suite = createBenchmarkSuite('Node.js Error')
suite
.add('Error', function () {
try {
new Error('test')
} catch (e) { }
})
.add('Error (stackTraceLimit=0)', function () {
const originalStackTraceLimit = Error.stackTraceLimit
Error.stackTraceLimit = 0
try {
new Error('test')
} catch (e) { }
finally {
Error.stackTraceLimit = originalStackTraceLimit;
}
})
.add('NodeError', function () {
try {
new TypeError('test')
} catch (e) { }
})
.add('NodeError (stackTraceLimit=0)', function () {
const originalStackTraceLimit = Error.stackTraceLimit
Error.stackTraceLimit = 0
try {
new TypeError('test')
} catch (e) { }
finally {
Error.stackTraceLimit = originalStackTraceLimit;
}
})
.add('NodeError Range', function () {
try {
new RangeError('test')
} catch (e) { }
})
.add('NodeError Range (stackTraceLimit=0)', function () {
const originalStackTraceLimit = Error.stackTraceLimit
Error.stackTraceLimit = 0
try {
new RangeError('test')
} catch (e) { }
finally {
Error.stackTraceLimit = originalStackTraceLimit;
}
})
.run({ async: false })
Based on this assumption, maybe we can find places on Node where we can safely ignore the stackTraceLimit, using this search, I found some places:
- https://github.com/nodejs/node/blob/0899bee48c64c4c2c5e2827a1ae5524a08542741/lib/internal/process/pre_execution.js#L215
- https://github.com/nodejs/node/blob/0899bee48c64c4c2c5e2827a1ae5524a08542741/lib/internal/modules/esm/worker.js#L66
- https://github.com/nodejs/node/blob/0899bee48c64c4c2c5e2827a1ae5524a08542741/lib/assert.js#L263
- https://github.com/nodejs/node/blob/0899bee48c64c4c2c5e2827a1ae5524a08542741/lib/internal/repl/utils.js#L131
- https://github.com/nodejs/node/blob/0899bee48c64c4c2c5e2827a1ae5524a08542741/lib/internal/streams/compose.js#L213
- https://github.com/nodejs/node/blob/0899bee48c64c4c2c5e2827a1ae5524a08542741/lib/internal/url.js#L151
- https://github.com/nodejs/node/blob/0899bee48c64c4c2c5e2827a1ae5524a08542741/lib/events.js#L501
- https://github.com/nodejs/node/blob/0899bee48c64c4c2c5e2827a1ae5524a08542741/lib/internal/encoding.js#L509
- https://github.com/nodejs/node/blob/0899bee48c64c4c2c5e2827a1ae5524a08542741/lib/internal/modules/esm/translators.js#L74
- https://github.com/nodejs/node/blob/6557c1c9b1206a85bb7d8e7450e8c3a4cff7c84b/lib/internal/worker/io.js#L277
- https://github.com/nodejs/node/blob/6557c1c9b1206a85bb7d8e7450e8c3a4cff7c84b/lib/internal/util.js#L375
- https://github.com/nodejs/node/blob/6557c1c9b1206a85bb7d8e7450e8c3a4cff7c84b/lib/querystring.js#L479
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with bench/error.js and reproduce the benchmark comparing normal errors with stackTraceLimit=0. Then review the listed Node.js files, including lib/assert.js, lib/events.js, lib/internal/process/pre_execution.js, and the ESM and stream modules, to determine where stack traces can be safely ignored. Done means identifying and validating the safe locations without changing cases that require the trace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100