mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
fs,cluster,net: assign error codes to remaining errors
After this commit, all errors thrown from JS code in lib have an error code. PR-URL: https://github.com/nodejs/node/pull/19373 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
fddcd6253b
commit
ab8bf26994
@ -777,6 +777,12 @@ Encoding provided to `util.TextDecoder()` API was not one of the
|
||||
A `Promise` that was callbackified via `util.callbackify()` was rejected with a
|
||||
falsy value.
|
||||
|
||||
<a id="ERR_FS_FILE_TOO_LARGE"></a>
|
||||
### ERR_FS_FILE_TOO_LARGE
|
||||
|
||||
An attempt has been made to read a file whose size is larger than the maximum
|
||||
allowed size for a `Buffer`.
|
||||
|
||||
<a id="ERR_FS_INVALID_SYMLINK_TYPE"></a>
|
||||
### ERR_FS_INVALID_SYMLINK_TYPE
|
||||
|
||||
|
@ -36,6 +36,7 @@ const fs = exports;
|
||||
const { Buffer } = require('buffer');
|
||||
const errors = require('internal/errors');
|
||||
const {
|
||||
ERR_FS_FILE_TOO_LARGE,
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_CALLBACK,
|
||||
ERR_OUT_OF_RANGE
|
||||
@ -347,8 +348,7 @@ function readFileAfterStat(err) {
|
||||
}
|
||||
|
||||
if (size > kMaxLength) {
|
||||
err = new RangeError('File size is greater than possible Buffer: ' +
|
||||
`0x${kMaxLength.toString(16)} bytes`);
|
||||
err = new ERR_FS_FILE_TOO_LARGE(size);
|
||||
return context.close(err);
|
||||
}
|
||||
|
||||
@ -421,6 +421,9 @@ function tryCreateBuffer(size, fd, isUserFd) {
|
||||
var threw = true;
|
||||
var buffer;
|
||||
try {
|
||||
if (size > kMaxLength) {
|
||||
throw new ERR_FS_FILE_TOO_LARGE(size);
|
||||
}
|
||||
buffer = Buffer.allocUnsafe(size);
|
||||
threw = false;
|
||||
} finally {
|
||||
|
@ -13,7 +13,7 @@ const {
|
||||
const binding = process.binding('fs');
|
||||
const { Buffer, kMaxLength } = require('buffer');
|
||||
const {
|
||||
ERR_BUFFER_TOO_LARGE,
|
||||
ERR_FS_FILE_TOO_LARGE,
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_METHOD_NOT_IMPLEMENTED,
|
||||
ERR_OUT_OF_RANGE
|
||||
@ -143,7 +143,7 @@ async function readFileHandle(filehandle, options) {
|
||||
return Buffer.alloc(0);
|
||||
|
||||
if (size > kMaxLength)
|
||||
throw new ERR_BUFFER_TOO_LARGE();
|
||||
throw new ERR_FS_FILE_TOO_LARGE(size);
|
||||
|
||||
const chunks = [];
|
||||
const chunkSize = Math.min(size, 16384);
|
||||
|
@ -8,6 +8,7 @@ const RoundRobinHandle = require('internal/cluster/round_robin_handle');
|
||||
const SharedHandle = require('internal/cluster/shared_handle');
|
||||
const Worker = require('internal/cluster/worker');
|
||||
const { internal, sendHelper, handles } = require('internal/cluster/utils');
|
||||
const { ERR_SOCKET_BAD_PORT } = require('internal/errors').codes;
|
||||
const keys = Object.keys;
|
||||
const cluster = new EventEmitter();
|
||||
const intercom = new EventEmitter();
|
||||
@ -115,8 +116,7 @@ function createWorkerProcess(id, env) {
|
||||
inspectPort = cluster.settings.inspectPort;
|
||||
|
||||
if (!isLegalPort(inspectPort)) {
|
||||
throw new TypeError('cluster.settings.inspectPort' +
|
||||
' is invalid');
|
||||
throw new ERR_SOCKET_BAD_PORT(inspectPort);
|
||||
}
|
||||
} else {
|
||||
inspectPort = process.debugPort + debugPortOffset;
|
||||
|
@ -651,6 +651,9 @@ E('ERR_ENCODING_INVALID_ENCODED_DATA',
|
||||
E('ERR_ENCODING_NOT_SUPPORTED', 'The "%s" encoding is not supported',
|
||||
RangeError);
|
||||
E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value', Error);
|
||||
E('ERR_FS_FILE_TOO_LARGE', 'File size (%s) is greater than possible Buffer: ' +
|
||||
`${kMaxLength} bytes`,
|
||||
RangeError);
|
||||
E('ERR_FS_INVALID_SYMLINK_TYPE',
|
||||
'Symlink type must be one of "dir", "file", or "junction". Received "%s"',
|
||||
Error); // Switch to TypeError. The current implementation does not seem right
|
||||
|
@ -928,7 +928,7 @@ function internalConnect(
|
||||
localAddress = localAddress || '::';
|
||||
err = self._handle.bind6(localAddress, localPort);
|
||||
} else {
|
||||
self.destroy(new TypeError('Invalid addressType: ' + addressType));
|
||||
self.destroy(new ERR_INVALID_ADDRESS_FAMILY(addressType));
|
||||
return;
|
||||
}
|
||||
debug('binding to localAddress: %s and localPort: %d (addressType: %d)',
|
||||
|
@ -207,6 +207,7 @@ function testRunnerMain() {
|
||||
function masterProcessMain() {
|
||||
const workers = JSON.parse(process.env.workers);
|
||||
const clusterSettings = JSON.parse(process.env.clusterSettings);
|
||||
const badPortError = { type: RangeError, code: 'ERR_SOCKET_BAD_PORT' };
|
||||
let debugPort = process.debugPort;
|
||||
|
||||
for (const worker of workers) {
|
||||
@ -234,36 +235,36 @@ function masterProcessMain() {
|
||||
clusterSettings.inspectPort = 'string';
|
||||
cluster.setupMaster(clusterSettings);
|
||||
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
|
||||
}, TypeError);
|
||||
}, badPortError);
|
||||
|
||||
return;
|
||||
} else if (clusterSettings.inspectPort === 'null') {
|
||||
clusterSettings.inspectPort = null;
|
||||
cluster.setupMaster(clusterSettings);
|
||||
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
|
||||
}, TypeError);
|
||||
}, badPortError);
|
||||
|
||||
return;
|
||||
} else if (clusterSettings.inspectPort === 'bignumber') {
|
||||
clusterSettings.inspectPort = 1293812;
|
||||
cluster.setupMaster(clusterSettings);
|
||||
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
|
||||
}, TypeError);
|
||||
}, badPortError);
|
||||
|
||||
return;
|
||||
} else if (clusterSettings.inspectPort === 'negativenumber') {
|
||||
clusterSettings.inspectPort = -9776;
|
||||
cluster.setupMaster(clusterSettings);
|
||||
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
|
||||
}, TypeError);
|
||||
}, badPortError);
|
||||
|
||||
return;
|
||||
} else if (clusterSettings.inspectPort === 'bignumberfunc') {
|
||||
@ -274,9 +275,9 @@ function masterProcessMain() {
|
||||
|
||||
cluster.setupMaster(clusterSettings);
|
||||
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
|
||||
}, TypeError);
|
||||
}, badPortError);
|
||||
|
||||
return;
|
||||
} else if (clusterSettings.inspectPort === 'strfunc') {
|
||||
@ -287,9 +288,9 @@ function masterProcessMain() {
|
||||
|
||||
cluster.setupMaster(clusterSettings);
|
||||
|
||||
assert.throws(() => {
|
||||
common.expectsError(() => {
|
||||
cluster.fork(params).on('exit', common.mustCall(checkExitCode));
|
||||
}, TypeError);
|
||||
}, badPortError);
|
||||
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user