diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-26 19:12:47 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-30 16:51:58 +0200 |
commit | 109cfa1511cb504866c44314d92552285a236b1c (patch) | |
tree | 2714839eac3b4ff88541719571e93069da584dd0 /lib | |
parent | 0deb27bd291a907816a337b08198c1c08f5a09e1 (diff) | |
download | android-node-v8-109cfa1511cb504866c44314d92552285a236b1c.tar.gz android-node-v8-109cfa1511cb504866c44314d92552285a236b1c.tar.bz2 android-node-v8-109cfa1511cb504866c44314d92552285a236b1c.zip |
errors: minor (SystemError) refactoring
This removes the former default values and the spread arguments
usage. That was unnecessary and now it does only what is necessary.
The `message` function got renamed to `getMessage` to outline that
it is actually a function and a helper function was inlined into
the SystemError constructor as it was only used there.
PR-URL: https://github.com/nodejs/node/pull/20337
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/errors.js | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 12d402a95f..adbc666276 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -78,16 +78,6 @@ function inspectValue(val) { ).split('\n'); } -function sysErrorMessage(prefix, ctx) { - let message = `${prefix}: ${ctx.syscall} returned ` + - `${ctx.code} (${ctx.message})`; - if (ctx.path !== undefined) - message += ` ${ctx.path}`; - if (ctx.dest !== undefined) - message += ` => ${ctx.dest}`; - return message; -} - // A specialized Error that includes an additional info property with // additional information about the error condition. // It has the properties present in a UVException but with a custom error @@ -97,9 +87,17 @@ function sysErrorMessage(prefix, ctx) { // The context passed into this error must have .code, .syscall and .message, // and may have .path and .dest. class SystemError extends Error { - constructor(key, context = {}) { - context = context || {}; - super(sysErrorMessage(message(key), context)); + constructor(key, context) { + const prefix = getMessage(key, []); + let message = `${prefix}: ${context.syscall} returned ` + + `${context.code} (${context.message})`; + + if (context.path !== undefined) + message += ` ${context.path}`; + if (context.dest !== undefined) + message += ` => ${context.dest}`; + + super(message); Object.defineProperty(this, kInfo, { configurable: false, enumerable: false, @@ -182,8 +180,8 @@ class SystemError extends Error { function makeSystemErrorWithCode(key) { return class NodeError extends SystemError { - constructor(...args) { - super(key, ...args); + constructor(ctx) { + super(key, ctx); } }; } @@ -191,7 +189,7 @@ function makeSystemErrorWithCode(key) { function makeNodeErrorWithCode(Base, key) { return class NodeError extends Base { constructor(...args) { - super(message(key, args)); + super(getMessage(key, args)); } get name() { @@ -484,7 +482,7 @@ function internalAssert(condition, message) { } } -function message(key, args = []) { +function getMessage(key, args) { const msg = messages.get(key); if (util === undefined) util = require('util'); @@ -691,7 +689,7 @@ module.exports = { exceptionWithHostPort, uvException, isStackOverflowError, - message, + getMessage, AssertionError, SystemError, codes, |