diff --git a/doc/api/errors.md b/doc/api/errors.md index 40b8e7ab74cf71..e0c7414564694f 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -570,6 +570,12 @@ The `'ERR_ARG_NOT_ITERABLE'` error code is used generically to identify that an iterable argument (i.e. a value that works with `for...of` loops) is required, but not provided to a Node.js API. + +### ERR_FALSY_VALUE_REJECTION + +The `ERR_FALSY_VALUE_REJECTION` error code is used by the `util.callbackify()` +API when a callbackified `Promise` is rejected with a falsy value (e.g. `null`). + ### ERR_INVALID_ARG_TYPE diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 7675f218dfed3b..ac286a6040ba9a 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -112,6 +112,7 @@ module.exports = exports = { // Note: Please try to keep these in alphabetical order E('ERR_ARG_NOT_ITERABLE', '%s must be iterable'); E('ERR_ASSERTION', (msg) => msg); +E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value'); E('ERR_INVALID_ARG_TYPE', invalidArgType); E('ERR_INVALID_CALLBACK', 'callback must be a function'); E('ERR_INVALID_FD', (fd) => `"fd" must be a positive integer: ${fd}`); @@ -149,7 +150,6 @@ E('ERR_SOCKET_BAD_TYPE', E('ERR_SOCKET_CANNOT_SEND', 'Unable to send data'); E('ERR_SOCKET_BAD_PORT', 'Port should be > 0 and < 65536'); E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running'); -E('FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value'); // Add new errors from here... function invalidArgType(name, expected, actual) { diff --git a/lib/util.js b/lib/util.js index e678237c1597f0..2b4714cfde1736 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1063,7 +1063,7 @@ function callbackifyOnRejected(reason, cb) { // occurred", we error-wrap so the callback consumer can distinguish between // "the promise rejected with null" or "the promise fulfilled with undefined". if (!reason) { - const newReason = new errors.Error('FALSY_VALUE_REJECTION'); + const newReason = new errors.Error('ERR_FALSY_VALUE_REJECTION'); newReason.reason = reason; reason = newReason; Error.captureStackTrace(reason, callbackifyOnRejected); diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js index fa793d4a7faccb..8bbc0fd36e970a 100644 --- a/test/parallel/test-util-callbackify.js +++ b/test/parallel/test-util-callbackify.js @@ -79,7 +79,7 @@ const values = [ if (err instanceof Error) { if ('reason' in err) { assert(!value); - assert.strictEqual(err.code, 'FALSY_VALUE_REJECTION'); + assert.strictEqual(err.code, 'ERR_FALSY_VALUE_REJECTION'); assert.strictEqual(err.reason, value); } else { assert.strictEqual(String(value).endsWith(err.message), true); @@ -100,7 +100,7 @@ const values = [ if (err instanceof Error) { if ('reason' in err) { assert(!value); - assert.strictEqual(err.code, 'FALSY_VALUE_REJECTION'); + assert.strictEqual(err.code, 'ERR_FALSY_VALUE_REJECTION'); assert.strictEqual(err.reason, value); } else { assert.strictEqual(String(value).endsWith(err.message), true); @@ -125,7 +125,7 @@ const values = [ if (err instanceof Error) { if ('reason' in err) { assert(!value); - assert.strictEqual(err.code, 'FALSY_VALUE_REJECTION'); + assert.strictEqual(err.code, 'ERR_FALSY_VALUE_REJECTION'); assert.strictEqual(err.reason, value); } else { assert.strictEqual(String(value).endsWith(err.message), true);