diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-18 02:29:39 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-23 02:55:54 +0100 |
commit | bfbce289c33b12aafb82bd5b45bcb4412850b28f (patch) | |
tree | fa9c21007fbe096b11e5a10d80de4b0af91137e4 /lib/os.js | |
parent | 1ed3c54ecbd72a33693e5954f86bcc9fd9b1cc09 (diff) | |
download | android-node-v8-bfbce289c33b12aafb82bd5b45bcb4412850b28f.tar.gz android-node-v8-bfbce289c33b12aafb82bd5b45bcb4412850b28f.tar.bz2 android-node-v8-bfbce289c33b12aafb82bd5b45bcb4412850b28f.zip |
lib: refactor Error.captureStackTrace() usage
When using `Errors.captureStackFrames` the error's stack property
is set again. This adds a helper function that wraps this functionality
in a simple API that does not only set the stack including the `code`
property but it also improves the performance to create the error.
The helper works for thrown errors and errors returned from wrapped
functions in case they are Node.js core errors.
PR-URL: https://github.com/nodejs/node/pull/26738
Fixes: https://github.com/nodejs/node/issues/26669
Fixes: https://github.com/nodejs/node/issues/20253
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'lib/os.js')
-rw-r--r-- | lib/os.js | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -26,7 +26,12 @@ const constants = internalBinding('constants').os; const { deprecate } = require('internal/util'); const isWindows = process.platform === 'win32'; -const { codes: { ERR_SYSTEM_ERROR } } = require('internal/errors'); +const { + codes: { + ERR_SYSTEM_ERROR + }, + hideStackFrames +} = require('internal/errors'); const { validateInt32 } = require('internal/validators'); const { @@ -47,16 +52,14 @@ const { } = internalBinding('os'); function getCheckedFunction(fn) { - return function checkError(...args) { + return hideStackFrames(function checkError(...args) { const ctx = {}; const ret = fn(...args, ctx); if (ret === undefined) { - const err = new ERR_SYSTEM_ERROR(ctx); - Error.captureStackTrace(err, checkError); - throw err; + throw new ERR_SYSTEM_ERROR(ctx); } return ret; - }; + }); } const getHomeDirectory = getCheckedFunction(_getHomeDirectory); |