Browse Source

errors: add missing ERR_ prefix on util.callbackify error

The `FALSY_VALUE_REJECTION` error code added by
https://github.com/nodejs/node/pull/12712 did not have the `ERR_` prefix,
nor was it added to the errors.md documentation. Add the prefix in for
consistency.

PR-URL: https://github.com/nodejs/node/pull/13604
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
v6
James M Snell 8 years ago
parent
commit
873e2f270f
  1. 6
      doc/api/errors.md
  2. 2
      lib/internal/errors.js
  3. 2
      lib/util.js
  4. 6
      test/parallel/test-util-callbackify.js

6
doc/api/errors.md

@ -576,6 +576,12 @@ The `ERR_CONSOLE_WRITABLE_STREAM` error code is thrown when `Console` is
instantiated without `stdout` stream or when `stdout` or `stderr` streams instantiated without `stdout` stream or when `stdout` or `stderr` streams
are not writable. are not writable.
<a id="ERR_FALSY_VALUE_REJECTION"></a>
### 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`).
<a id="ERR_INDEX_OUT_OF_RANGE"></a> <a id="ERR_INDEX_OUT_OF_RANGE"></a>
### ERR_INDEX_OUT_OF_RANGE ### ERR_INDEX_OUT_OF_RANGE

2
lib/internal/errors.js

@ -115,6 +115,7 @@ E('ERR_ASSERTION', (msg) => msg);
E('ERR_CONSOLE_WRITABLE_STREAM', E('ERR_CONSOLE_WRITABLE_STREAM',
(name) => `Console expects a writable stream instance for ${name}`); (name) => `Console expects a writable stream instance for ${name}`);
E('ERR_CPU_USAGE', (errMsg) => `Unable to obtain cpu usage ${errMsg}`); E('ERR_CPU_USAGE', (errMsg) => `Unable to obtain cpu usage ${errMsg}`);
E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
E('ERR_HTTP_HEADERS_SENT', E('ERR_HTTP_HEADERS_SENT',
'Cannot render headers after they are sent to the client'); 'Cannot render headers after they are sent to the client');
E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.'); E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.');
@ -166,7 +167,6 @@ E('ERR_SOCKET_BAD_PORT', 'Port should be > 0 and < 65536');
E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running'); E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running');
E('ERR_V8BREAKITERATOR', 'full ICU data not installed. ' + E('ERR_V8BREAKITERATOR', 'full ICU data not installed. ' +
'See https://github.com/nodejs/node/wiki/Intl'); 'See https://github.com/nodejs/node/wiki/Intl');
E('FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
// Add new errors from here... // Add new errors from here...
function invalidArgType(name, expected, actual) { function invalidArgType(name, expected, actual) {

2
lib/util.js

@ -1054,7 +1054,7 @@ function callbackifyOnRejected(reason, cb) {
// occurred", we error-wrap so the callback consumer can distinguish between // occurred", we error-wrap so the callback consumer can distinguish between
// "the promise rejected with null" or "the promise fulfilled with undefined". // "the promise rejected with null" or "the promise fulfilled with undefined".
if (!reason) { if (!reason) {
const newReason = new errors.Error('FALSY_VALUE_REJECTION'); const newReason = new errors.Error('ERR_FALSY_VALUE_REJECTION');
newReason.reason = reason; newReason.reason = reason;
reason = newReason; reason = newReason;
Error.captureStackTrace(reason, callbackifyOnRejected); Error.captureStackTrace(reason, callbackifyOnRejected);

6
test/parallel/test-util-callbackify.js

@ -79,7 +79,7 @@ const values = [
if (err instanceof Error) { if (err instanceof Error) {
if ('reason' in err) { if ('reason' in err) {
assert(!value); assert(!value);
assert.strictEqual(err.code, 'FALSY_VALUE_REJECTION'); assert.strictEqual(err.code, 'ERR_FALSY_VALUE_REJECTION');
assert.strictEqual(err.reason, value); assert.strictEqual(err.reason, value);
} else { } else {
assert.strictEqual(String(value).endsWith(err.message), true); assert.strictEqual(String(value).endsWith(err.message), true);
@ -100,7 +100,7 @@ const values = [
if (err instanceof Error) { if (err instanceof Error) {
if ('reason' in err) { if ('reason' in err) {
assert(!value); assert(!value);
assert.strictEqual(err.code, 'FALSY_VALUE_REJECTION'); assert.strictEqual(err.code, 'ERR_FALSY_VALUE_REJECTION');
assert.strictEqual(err.reason, value); assert.strictEqual(err.reason, value);
} else { } else {
assert.strictEqual(String(value).endsWith(err.message), true); assert.strictEqual(String(value).endsWith(err.message), true);
@ -125,7 +125,7 @@ const values = [
if (err instanceof Error) { if (err instanceof Error) {
if ('reason' in err) { if ('reason' in err) {
assert(!value); assert(!value);
assert.strictEqual(err.code, 'FALSY_VALUE_REJECTION'); assert.strictEqual(err.code, 'ERR_FALSY_VALUE_REJECTION');
assert.strictEqual(err.reason, value); assert.strictEqual(err.reason, value);
} else { } else {
assert.strictEqual(String(value).endsWith(err.message), true); assert.strictEqual(String(value).endsWith(err.message), true);

Loading…
Cancel
Save