mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
errors: port internal/process errors to internal/errors
* Assign codes to the handful of errors reported by internal/process/*.js * Include documentation for the new error codes * Improve error messages * Improve test coverage for process.nextTick PR-URL: https://github.com/nodejs/node/pull/11294 Ref: https://github.com/nodejs/node/issues/11273 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
This commit is contained in:
1 parent
468275ac79
commit
e75bc87d22
9 files changed
+191
-54
No files matched your search
@@ -80,4 +80,32 @@ module.exports = exports = {
|
||||
//
|
||||
// Note: Please try to keep these in alphabetical order
|
||||
E('ERR_ASSERTION', (msg) => msg);
|
||||
E('ERR_INVALID_ARG_TYPE', invalidArgType);
|
||||
E('ERR_INVALID_CALLBACK', 'callback must be a function');
|
||||
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
|
||||
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
|
||||
E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
|
||||
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
|
||||
// Add new errors from here...
|
||||
|
||||
function invalidArgType(name, expected, actual) {
|
||||
assert(name, 'name is required');
|
||||
assert(expected, 'expected is required');
|
||||
var msg = `The "${name}" argument must be `;
|
||||
if (Array.isArray(expected)) {
|
||||
var len = expected.length;
|
||||
expected = expected.map((i) => String(i));
|
||||
if (len > 1) {
|
||||
msg += `one of type ${expected.slice(0, len - 1).join(', ')}, or ` +
|
||||
expected[len - 1];
|
||||
} else {
|
||||
msg += `of type ${expected[0]}`;
|
||||
}
|
||||
} else {
|
||||
msg += `of type ${String(expected)}`;
|
||||
}
|
||||
if (arguments.length >= 3) {
|
||||
msg += `. Received type ${actual !== null ? typeof actual : 'null'}`;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
Reference in new issue
Block a user