mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
errors,buffer: port errors to internal/errors
PR-URL: https://github.com/nodejs/node/pull/13976 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
1 parent
1562fb9ea7
commit
dbfe8c4ea2
28 files changed
+342
-143
No files matched your search
+35
-2
@@ -109,9 +109,11 @@ module.exports = exports = {
|
||||
// Note: Please try to keep these in alphabetical order
|
||||
E('ERR_ARG_NOT_ITERABLE', '%s must be iterable');
|
||||
E('ERR_ASSERTION', '%s');
|
||||
E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds);
|
||||
E('ERR_CONSOLE_WRITABLE_STREAM',
|
||||
'Console expects a writable stream instance for %s');
|
||||
E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s');
|
||||
E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported');
|
||||
E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
|
||||
E('ERR_HTTP_HEADERS_SENT',
|
||||
'Cannot render headers after they are sent to the client');
|
||||
@@ -127,6 +129,7 @@ E('ERR_INVALID_ARRAY_LENGTH',
|
||||
return `The "${name}" array must have a length of ${
|
||||
length}. Received length ${actual}`;
|
||||
});
|
||||
E('ERR_INVALID_BUFFER_SIZE', 'Buffer size must be a multiple of %s');
|
||||
E('ERR_INVALID_CALLBACK', 'Callback must be a function');
|
||||
E('ERR_INVALID_CHAR', 'Invalid character in %s');
|
||||
E('ERR_INVALID_CURSOR_POS',
|
||||
@@ -173,6 +176,7 @@ E('ERR_TRANSFORM_ALREADY_TRANSFORMING',
|
||||
'Calling transform done when still transforming');
|
||||
E('ERR_TRANSFORM_WITH_LENGTH_0',
|
||||
'Calling transform done when writableState.length != 0');
|
||||
E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s');
|
||||
E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s');
|
||||
E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
|
||||
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
|
||||
@@ -183,8 +187,29 @@ E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' +
|
||||
function invalidArgType(name, expected, actual) {
|
||||
const assert = lazyAssert();
|
||||
assert(name, 'name is required');
|
||||
const type = name.includes('.') ? 'property' : 'argument';
|
||||
var msg = `The "${name}" ${type} must be ${oneOf(expected, 'type')}`;
|
||||
|
||||
// determiner: 'must be' or 'must not be'
|
||||
let determiner;
|
||||
if (expected.includes('not ')) {
|
||||
determiner = 'must not be';
|
||||
expected = expected.split('not ')[1];
|
||||
} else {
|
||||
determiner = 'must be';
|
||||
}
|
||||
|
||||
let msg;
|
||||
if (Array.isArray(name)) {
|
||||
var names = name.map((val) => `"${val}"`).join(', ');
|
||||
msg = `The ${names} arguments ${determiner} ${oneOf(expected, 'type')}`;
|
||||
} else if (name.includes(' argument')) {
|
||||
// for the case like 'first argument'
|
||||
msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
|
||||
} else {
|
||||
const type = name.includes('.') ? 'property' : 'argument';
|
||||
msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, 'type')}`;
|
||||
}
|
||||
|
||||
// if actual value received, output it
|
||||
if (arguments.length >= 3) {
|
||||
msg += `. Received type ${actual !== null ? typeof actual : 'null'}`;
|
||||
}
|
||||
@@ -231,3 +256,11 @@ function oneOf(expected, thing) {
|
||||
return `of ${thing} ${String(expected)}`;
|
||||
}
|
||||
}
|
||||
|
||||
function bufferOutOfBounds(name, isWriting) {
|
||||
if (isWriting) {
|
||||
return 'Attempt to write outside buffer bounds';
|
||||
} else {
|
||||
return `"${name}" is outside of buffer bounds`;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user