lib: enforce ASCII order in error code imports

PR-URL: https://github.com/nodejs/node/pull/52625
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Antoine du Hamel 2024-04-23 19:05:38 +02:00 committed by GitHub
parent ff826069a8
commit 231548b5cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
59 changed files with 268 additions and 168 deletions

View File

@ -185,6 +185,7 @@ rules:
- groups: [['&&', '||']]
# Custom rules in tools/eslint-rules
node-core/alphabetize-errors: error
node-core/alphabetize-primordials: error
node-core/avoid-prototype-pollution: error
node-core/lowercase-name-for-primitive: error

View File

@ -72,14 +72,16 @@ const {
traceEnd,
getNextTraceEventId,
} = require('internal/http');
const { ConnResetException, codes } = require('internal/errors');
const {
ERR_HTTP_HEADERS_SENT,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_HTTP_TOKEN,
ERR_INVALID_PROTOCOL,
ERR_UNESCAPED_CHARACTERS,
} = codes;
ConnResetException,
codes: {
ERR_HTTP_HEADERS_SENT,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_HTTP_TOKEN,
ERR_INVALID_PROTOCOL,
ERR_UNESCAPED_CHARACTERS,
},
} = require('internal/errors');
const {
validateInteger,
validateBoolean,

View File

@ -56,21 +56,21 @@ const {
} = require('internal/async_hooks');
const {
codes: {
ERR_HTTP_BODY_NOT_ALLOWED,
ERR_HTTP_CONTENT_LENGTH_MISMATCH,
ERR_HTTP_HEADERS_SENT,
ERR_HTTP_INVALID_HEADER_VALUE,
ERR_HTTP_TRAILER_INVALID,
ERR_HTTP_BODY_NOT_ALLOWED,
ERR_INVALID_HTTP_TOKEN,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_CHAR,
ERR_INVALID_HTTP_TOKEN,
ERR_METHOD_NOT_IMPLEMENTED,
ERR_STREAM_CANNOT_PIPE,
ERR_STREAM_ALREADY_FINISHED,
ERR_STREAM_WRITE_AFTER_END,
ERR_STREAM_NULL_VALUES,
ERR_STREAM_CANNOT_PIPE,
ERR_STREAM_DESTROYED,
ERR_STREAM_NULL_VALUES,
ERR_STREAM_WRITE_AFTER_END,
},
hideStackFrames,
} = require('internal/errors');

View File

@ -70,17 +70,17 @@ const {
const { IncomingMessage } = require('_http_incoming');
const {
ConnResetException,
codes,
codes: {
ERR_HTTP_HEADERS_SENT,
ERR_HTTP_INVALID_STATUS_CODE,
ERR_HTTP_REQUEST_TIMEOUT,
ERR_HTTP_SOCKET_ASSIGNED,
ERR_HTTP_SOCKET_ENCODING,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_CHAR,
ERR_OUT_OF_RANGE,
},
} = require('internal/errors');
const {
ERR_HTTP_REQUEST_TIMEOUT,
ERR_HTTP_HEADERS_SENT,
ERR_HTTP_INVALID_STATUS_CODE,
ERR_HTTP_SOCKET_ENCODING,
ERR_HTTP_SOCKET_ASSIGNED,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_CHAR,
} = codes;
const {
kEmptyObject,
promisify,
@ -467,7 +467,7 @@ function storeHTTPOptions(options) {
}
if (this.requestTimeout > 0 && this.headersTimeout > 0 && this.headersTimeout > this.requestTimeout) {
throw new codes.ERR_OUT_OF_RANGE('headersTimeout', '<= requestTimeout', headersTimeout);
throw new ERR_OUT_OF_RANGE('headersTimeout', '<= requestTimeout', headersTimeout);
}
const keepAliveTimeout = options.keepAliveTimeout;

View File

@ -66,23 +66,25 @@ const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap');
const { owner_symbol } = require('internal/async_hooks').symbols;
const { isArrayBufferView } = require('internal/util/types');
const { SecureContext: NativeSecureContext } = internalBinding('crypto');
const { ConnResetException, codes } = require('internal/errors');
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_MULTIPLE_CALLBACK,
ERR_SOCKET_CLOSED,
ERR_TLS_ALPN_CALLBACK_INVALID_RESULT,
ERR_TLS_ALPN_CALLBACK_WITH_PROTOCOLS,
ERR_TLS_DH_PARAM_SIZE,
ERR_TLS_HANDSHAKE_TIMEOUT,
ERR_TLS_INVALID_CONTEXT,
ERR_TLS_RENEGOTIATION_DISABLED,
ERR_TLS_REQUIRED_SERVER_NAME,
ERR_TLS_SESSION_ATTACK,
ERR_TLS_SNI_FROM_SERVER,
ERR_TLS_INVALID_STATE,
} = codes;
ConnResetException,
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_MULTIPLE_CALLBACK,
ERR_SOCKET_CLOSED,
ERR_TLS_ALPN_CALLBACK_INVALID_RESULT,
ERR_TLS_ALPN_CALLBACK_WITH_PROTOCOLS,
ERR_TLS_DH_PARAM_SIZE,
ERR_TLS_HANDSHAKE_TIMEOUT,
ERR_TLS_INVALID_CONTEXT,
ERR_TLS_INVALID_STATE,
ERR_TLS_RENEGOTIATION_DISABLED,
ERR_TLS_REQUIRED_SERVER_NAME,
ERR_TLS_SESSION_ATTACK,
ERR_TLS_SNI_FROM_SERVER,
},
} = require('internal/errors');
const { onpskexchange: kOnPskExchange } = internalBinding('symbols');
const {
getOptionValue,

View File

@ -103,8 +103,8 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_BUFFER_SIZE,
ERR_OUT_OF_RANGE,
ERR_MISSING_ARGS,
ERR_OUT_OF_RANGE,
ERR_UNKNOWN_ENCODING,
},
genericNodeError,

View File

@ -64,16 +64,15 @@ const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap');
const {
AbortError,
codes: errorCodes,
codes: {
ERR_CHILD_PROCESS_IPC_REQUIRED,
ERR_CHILD_PROCESS_STDIO_MAXBUFFER,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_OUT_OF_RANGE,
},
genericNodeError,
} = require('internal/errors');
const {
ERR_INVALID_ARG_VALUE,
ERR_CHILD_PROCESS_IPC_REQUIRED,
ERR_CHILD_PROCESS_STDIO_MAXBUFFER,
ERR_INVALID_ARG_TYPE,
ERR_OUT_OF_RANGE,
} = errorCodes;
const { clearTimeout, setTimeout } = require('timers');
const { getValidatedPath } = require('internal/fs/utils');
const {

View File

@ -34,24 +34,27 @@ const {
SymbolDispose,
} = primordials;
const errors = require('internal/errors');
const {
ErrnoException,
ExceptionWithHostPort,
codes: {
ERR_BUFFER_OUT_OF_BOUNDS,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_FD_TYPE,
ERR_MISSING_ARGS,
ERR_SOCKET_ALREADY_BOUND,
ERR_SOCKET_BAD_BUFFER_SIZE,
ERR_SOCKET_BUFFER_SIZE,
ERR_SOCKET_DGRAM_IS_CONNECTED,
ERR_SOCKET_DGRAM_NOT_CONNECTED,
ERR_SOCKET_DGRAM_NOT_RUNNING,
},
} = require('internal/errors');
const {
kStateSymbol,
_createSocketHandle,
newHandle,
} = require('internal/dgram');
const {
ERR_BUFFER_OUT_OF_BOUNDS,
ERR_INVALID_ARG_TYPE,
ERR_MISSING_ARGS,
ERR_SOCKET_ALREADY_BOUND,
ERR_SOCKET_BAD_BUFFER_SIZE,
ERR_SOCKET_BUFFER_SIZE,
ERR_SOCKET_DGRAM_IS_CONNECTED,
ERR_SOCKET_DGRAM_NOT_CONNECTED,
ERR_SOCKET_DGRAM_NOT_RUNNING,
ERR_INVALID_FD_TYPE,
} = errors.codes;
const {
isInt32,
validateAbortSignal,
@ -97,11 +100,6 @@ function lazyLoadCluster() {
return _cluster;
}
const {
ErrnoException,
ExceptionWithHostPort,
} = errors;
function Socket(type, listener) {
FunctionPrototypeCall(EventEmitter, this);
let lookup;

View File

@ -31,12 +31,12 @@ const cares = internalBinding('cares_wrap');
const { isIP } = require('internal/net');
const { customPromisifyArgs } = require('internal/util');
const {
DNSException,
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_MISSING_ARGS,
},
DNSException,
} = require('internal/errors');
const {
bindDefaultResolver,

View File

@ -66,13 +66,13 @@ let kResistStopPropagation;
const {
AbortError,
kEnhanceStackBeforeInspector,
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_THIS,
ERR_UNHANDLED_ERROR,
},
genericNodeError,
kEnhanceStackBeforeInspector,
} = require('internal/errors');
const {

View File

@ -70,13 +70,13 @@ const { Buffer } = require('buffer');
const { isBuffer: BufferIsBuffer } = Buffer;
const BufferToString = uncurryThis(Buffer.prototype.toString);
const {
AbortError,
aggregateTwoErrors,
codes: {
ERR_ACCESS_DENIED,
ERR_FS_FILE_TOO_LARGE,
ERR_INVALID_ARG_VALUE,
},
AbortError,
} = require('internal/errors');
const {

View File

@ -14,8 +14,8 @@ const {
const {
codes: {
ERR_UNAVAILABLE_DURING_EXIT,
ERR_INVALID_ARG_VALUE,
ERR_UNAVAILABLE_DURING_EXIT,
},
} = require('internal/errors');
const AssertionError = require('internal/assert/assertion_error');

View File

@ -56,11 +56,11 @@ const { inspect } = require('internal/util/inspect');
const {
codes: {
ERR_BUFFER_TOO_LARGE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_THIS,
ERR_INVALID_STATE,
ERR_BUFFER_TOO_LARGE,
ERR_INVALID_THIS,
},
} = require('internal/errors');

View File

@ -23,7 +23,9 @@ if (credentials.implementsPosixCredentials) {
// ---- compare the setups side-by-side -----
const {
codes: { ERR_WORKER_UNSUPPORTED_OPERATION },
codes: {
ERR_WORKER_UNSUPPORTED_OPERATION,
},
} = require('internal/errors');
function wrappedUmask(mask) {

View File

@ -40,12 +40,12 @@ const {
const { trace } = internalBinding('trace_events');
const {
isStackOverflowError,
codes: {
ERR_CONSOLE_WRITABLE_STREAM,
ERR_INVALID_ARG_VALUE,
ERR_INCOMPATIBLE_OPTION_PAIR,
ERR_INVALID_ARG_VALUE,
},
isStackOverflowError,
} = require('internal/errors');
const {
validateArray,

View File

@ -35,8 +35,8 @@ const {
const {
codes: {
ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS,
ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE,
ERR_CRYPTO_INVALID_JWK,
ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE,
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,

View File

@ -40,8 +40,8 @@ const { Buffer, kMaxLength } = require('buffer');
const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_OUT_OF_RANGE,
ERR_OPERATION_FAILED,
ERR_OUT_OF_RANGE,
},
} = require('internal/errors');

View File

@ -43,7 +43,6 @@ const {
const normalizeHashName = require('internal/crypto/hashnames');
const {
hideStackFrames,
codes: {
ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED,
ERR_CRYPTO_ENGINE_UNKNOWN,
@ -51,6 +50,7 @@ const {
ERR_INVALID_ARG_VALUE,
ERR_OUT_OF_RANGE,
},
hideStackFrames,
} = require('internal/errors');
const {

View File

@ -5,7 +5,9 @@ const {
Symbol,
} = primordials;
const { codes } = require('internal/errors');
const { codes: {
ERR_SOCKET_BAD_TYPE,
} } = require('internal/errors');
const { UDP } = internalBinding('udp_wrap');
const { guessHandleType } = require('internal/util');
const {
@ -13,9 +15,6 @@ const {
validateFunction,
} = require('internal/validators');
const { UV_EINVAL } = internalBinding('uv');
const {
ERR_SOCKET_BAD_TYPE,
} = codes;
const kStateSymbol = Symbol('state symbol');
let dns; // Lazy load for startup performance.

View File

@ -8,11 +8,11 @@ const {
} = primordials;
const {
DNSException,
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
},
DNSException,
} = require('internal/errors');
const {

View File

@ -44,7 +44,14 @@ const {
ADDRGETNETWORKPARAMS,
CANCELLED,
} = dnsErrorCodes;
const { codes, DNSException } = require('internal/errors');
const {
DNSException,
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_MISSING_ARGS,
},
} = require('internal/errors');
const { isIP } = require('internal/net');
const {
getaddrinfo,
@ -56,11 +63,6 @@ const {
DNS_ORDER_IPV4_FIRST,
DNS_ORDER_IPV6_FIRST,
} = internalBinding('cares_wrap');
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_MISSING_ARGS,
} = codes;
const {
validateBoolean,
validateNumber,

View File

@ -11,7 +11,13 @@ const {
Symbol,
} = primordials;
const errors = require('internal/errors');
const {
codes: {
ERR_DNS_SET_SERVERS_FAILED,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_IP_ADDRESS,
},
} = require('internal/errors');
const { isIP } = require('internal/net');
const { getOptionValue } = require('internal/options');
const {
@ -28,11 +34,6 @@ function lazyBinding() {
const IANA_DNS_PORT = 53;
const IPv6RE = /^\[([^[\]]*)\]/;
const addrSplitRE = /(^.+?)(?::(\d+))?$/;
const {
ERR_DNS_SET_SERVERS_FAILED,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_IP_ADDRESS,
} = errors.codes;
const {
namespace: {

View File

@ -1,5 +1,5 @@
/* eslint node-core/documented-errors: "error" */
/* eslint node-core/alphabetize-errors: "error" */
/* eslint node-core/alphabetize-errors: ["error", {checkErrorDeclarations: true}] */
/* eslint node-core/prefer-util-format-errors: "error" */
'use strict';

View File

@ -25,10 +25,10 @@ const {
const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_EVENT_RECURSION,
ERR_MISSING_ARGS,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_THIS,
ERR_MISSING_ARGS,
},
} = require('internal/errors');
const {

View File

@ -3,18 +3,7 @@
// This file is a modified version of the fs-extra's copySync method.
const { areIdentical, isSrcSubdir } = require('internal/fs/cp/cp');
const { codes } = require('internal/errors');
const {
os: {
errno: {
EEXIST,
EISDIR,
EINVAL,
ENOTDIR,
},
},
} = internalBinding('constants');
const {
const { codes: {
ERR_FS_CP_DIR_TO_NON_DIR,
ERR_FS_CP_EEXIST,
ERR_FS_CP_EINVAL,
@ -25,7 +14,17 @@ const {
ERR_FS_CP_UNKNOWN,
ERR_FS_EISDIR,
ERR_INVALID_RETURN_VALUE,
} = codes;
} } = require('internal/errors');
const {
os: {
errno: {
EEXIST,
EISDIR,
EINVAL,
ENOTDIR,
},
},
} = internalBinding('constants');
const {
chmodSync,
copyFileSync,

View File

@ -35,6 +35,8 @@ const { isBuffer: BufferIsBuffer } = Buffer;
const BufferToString = uncurryThis(Buffer.prototype.toString);
const {
AbortError,
aggregateTwoErrors,
codes: {
ERR_ACCESS_DENIED,
ERR_FS_FILE_TOO_LARGE,
@ -42,8 +44,6 @@ const {
ERR_INVALID_STATE,
ERR_METHOD_NOT_IMPLEMENTED,
},
AbortError,
aggregateTwoErrors,
} = require('internal/errors');
const { isArrayBufferView } = require('internal/util/types');

View File

@ -31,6 +31,7 @@ const permission = require('internal/process/permission');
const { Buffer } = require('buffer');
const {
UVException,
codes: {
ERR_FS_EISDIR,
ERR_FS_INVALID_SYMLINK_TYPE,
@ -40,7 +41,6 @@ const {
ERR_OUT_OF_RANGE,
},
hideStackFrames,
UVException,
} = require('internal/errors');
const {
isArrayBufferView,

View File

@ -24,8 +24,8 @@ const { inspect } = require('util');
const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_THIS,
ERR_OUT_OF_RANGE,
},

View File

@ -71,6 +71,7 @@ const {
},
} = require('internal/async_hooks');
const {
AbortError,
aggregateTwoErrors,
codes: {
ERR_HTTP2_ALTSVC_INVALID_ORIGIN,
@ -120,7 +121,6 @@ const {
ERR_SOCKET_CLOSED,
},
hideStackFrames,
AbortError,
} = require('internal/errors');
const {
isUint32,

View File

@ -8,7 +8,9 @@ const {
const Buffer = require('buffer').Buffer;
const { writeBuffer } = internalBinding('fs');
const errors = require('internal/errors');
const {
UVException,
} = require('internal/errors');
// IPv4 Segment
const v4Seg = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])';
@ -58,7 +60,7 @@ function makeSyncWrite(fd) {
const ctx = {};
writeBuffer(fd, chunk, 0, chunk.length, null, undefined, ctx);
if (ctx.errno !== undefined) {
const ex = new errors.UVException(ctx);
const ex = new UVException(ctx);
ex.errno = ctx.errno;
return cb(ex);
}

View File

@ -43,8 +43,8 @@ const {
const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_MISSING_ARGS,
},
} = require('internal/errors');

View File

@ -10,9 +10,9 @@ const path = require('path');
const {
codes: {
ERR_EVAL_ESM_CANNOT_PRINT,
ERR_INVALID_ARG_TYPE,
ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET,
ERR_EVAL_ESM_CANNOT_PRINT,
},
} = require('internal/errors');
const { pathToFileURL } = require('internal/url');

View File

@ -4,7 +4,9 @@
// run in the worker thread.
const {
codes: { ERR_WORKER_UNSUPPORTED_OPERATION },
codes: {
ERR_WORKER_UNSUPPORTED_OPERATION,
},
} = require('internal/errors');
function unavailable(name) {

View File

@ -33,12 +33,11 @@ const {
SymbolDispose,
} = primordials;
const { codes } = require('internal/errors');
const {
const { codes: {
ERR_INVALID_ARG_VALUE,
ERR_USE_AFTER_CLOSE,
} = codes;
} } = require('internal/errors');
const {
validateAbortSignal,
validateArray,

View File

@ -9,7 +9,9 @@ const {
const { CSI } = require('internal/readline/utils');
const { validateBoolean, validateInteger } = require('internal/validators');
const { isWritable } = require('internal/streams/utils');
const { codes: { ERR_INVALID_ARG_TYPE } } = require('internal/errors');
const { codes: {
ERR_INVALID_ARG_TYPE,
} } = require('internal/errors');
const {
kClearToLineBeginning,

View File

@ -6,7 +6,9 @@ const {
const {
AbortError,
codes,
codes: {
ERR_INVALID_ARG_TYPE,
},
} = require('internal/errors');
const {
@ -16,7 +18,6 @@ const {
} = require('internal/streams/utils');
const eos = require('internal/streams/end-of-stream');
const { ERR_INVALID_ARG_TYPE } = codes;
let addAbortListener;
// This method is inlined here for readable-stream

View File

@ -3,12 +3,13 @@
const {
Symbol,
} = primordials;
const {
AbortError,
aggregateTwoErrors,
codes: {
ERR_MULTIPLE_CALLBACK,
},
AbortError,
} = require('internal/errors');
const {
kIsDestroyed,

View File

@ -11,12 +11,11 @@ const {
const {
AbortError,
codes,
codes: {
ERR_INVALID_ARG_TYPE,
ERR_STREAM_PREMATURE_CLOSE,
},
} = require('internal/errors');
const {
ERR_INVALID_ARG_TYPE,
ERR_STREAM_PREMATURE_CLOSE,
} = codes;
const {
kEmptyObject,
once,

View File

@ -16,13 +16,13 @@ const {
const { AbortController, AbortSignal } = require('internal/abort_controller');
const {
AbortError,
codes: {
ERR_INVALID_ARG_VALUE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_MISSING_ARGS,
ERR_OUT_OF_RANGE,
},
AbortError,
} = require('internal/errors');
const {
validateAbortSignal,

View File

@ -15,6 +15,7 @@ const { once } = require('internal/util');
const destroyImpl = require('internal/streams/destroy');
const Duplex = require('internal/streams/duplex');
const {
AbortError,
aggregateTwoErrors,
codes: {
ERR_INVALID_ARG_TYPE,
@ -23,7 +24,6 @@ const {
ERR_STREAM_DESTROYED,
ERR_STREAM_PREMATURE_CLOSE,
},
AbortError,
} = require('internal/errors');
const {

View File

@ -74,6 +74,7 @@ const {
} = require('internal/streams/utils');
const {
AbortError,
aggregateTwoErrors,
codes: {
ERR_INVALID_ARG_TYPE,
@ -83,7 +84,6 @@ const {
ERR_STREAM_UNSHIFT_AFTER_END_EVENT,
ERR_UNKNOWN_ENCODING,
},
AbortError,
} = require('internal/errors');
const { validateObject } = require('internal/validators');

View File

@ -32,7 +32,10 @@ const {
} = require('internal/util');
const {
AbortError,
codes: { ERR_INVALID_STATE, ERR_INVALID_ARG_VALUE },
codes: {
ERR_INVALID_ARG_VALUE,
ERR_INVALID_STATE,
},
} = require('internal/errors');
const PriorityQueue = require('internal/priority_queue');

View File

@ -42,8 +42,8 @@ const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_TEST_FAILURE,
ERR_OUT_OF_RANGE,
ERR_TEST_FAILURE,
},
} = require('internal/errors');
const {

View File

@ -33,11 +33,11 @@ const { queueMicrotask } = require('internal/process/task_queues');
const { AsyncResource } = require('async_hooks');
const { AbortController } = require('internal/abort_controller');
const {
AbortError,
codes: {
ERR_INVALID_ARG_TYPE,
ERR_TEST_FAILURE,
},
AbortError,
} = require('internal/errors');
const { MockTracker } = require('internal/test_runner/mock/mock');
const { TestsStream } = require('internal/test_runner/tests_stream');

View File

@ -50,8 +50,8 @@ const {
ERR_UNKNOWN_SIGNAL,
},
isErrorStackTraceLimitWritable,
uvErrmapGet,
overrideStackTrace,
uvErrmapGet,
} = require('internal/errors');
const { signals } = internalBinding('constants').os;
const {

View File

@ -1,7 +1,9 @@
'use strict';
const { BuiltinModule: { normalizeRequirableId } } = require('internal/bootstrap/realm');
const { Module, wrapSafe } = require('internal/modules/cjs/loader');
const { codes: { ERR_UNKNOWN_BUILTIN_MODULE } } = require('internal/errors');
const { codes: {
ERR_UNKNOWN_BUILTIN_MODULE,
} } = require('internal/errors');
const { getCodePath, isSea } = internalBinding('sea');
// This is roughly the same as:

View File

@ -45,8 +45,8 @@ const {
codes: {
ERR_INVALID_ARG_VALUE,
ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
ERR_PARSE_ARGS_UNKNOWN_OPTION,
ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
ERR_PARSE_ARGS_UNKNOWN_OPTION,
},
} = require('internal/errors');

View File

@ -5,9 +5,9 @@ const {
} = require('internal/validators');
const {
codes: {
ERR_DUPLICATE_STARTUP_SNAPSHOT_MAIN_FUNCTION,
ERR_NOT_BUILDING_SNAPSHOT,
ERR_NOT_SUPPORTED_IN_SNAPSHOT,
ERR_DUPLICATE_STARTUP_SNAPSHOT_MAIN_FUNCTION,
},
} = require('internal/errors');

View File

@ -20,14 +20,14 @@ const {
} = primordials;
const {
hideStackFrames,
codes: {
ERR_SOCKET_BAD_PORT: { HideStackFramesError: ERR_SOCKET_BAD_PORT },
ERR_INVALID_ARG_TYPE: { HideStackFramesError: ERR_INVALID_ARG_TYPE },
ERR_INVALID_ARG_VALUE: { HideStackFramesError: ERR_INVALID_ARG_VALUE },
ERR_OUT_OF_RANGE: { HideStackFramesError: ERR_OUT_OF_RANGE },
ERR_SOCKET_BAD_PORT: { HideStackFramesError: ERR_SOCKET_BAD_PORT },
ERR_UNKNOWN_SIGNAL: { HideStackFramesError: ERR_UNKNOWN_SIGNAL },
},
hideStackFrames,
} = require('internal/errors');
const { normalizeEncoding } = require('internal/util');
const {

View File

@ -52,6 +52,7 @@ const {
} = require('buffer');
const {
AbortError,
ErrnoException,
codes: {
ERR_INVALID_ARG_TYPE,
@ -59,7 +60,6 @@ const {
ERR_INVALID_STATE,
ERR_STREAM_PREMATURE_CLOSE,
},
AbortError,
} = require('internal/errors');
const {

View File

@ -30,8 +30,8 @@ const {
AbortError,
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_STATE,
ERR_INVALID_THIS,
ERR_OUT_OF_RANGE,

View File

@ -19,8 +19,8 @@ const {
const {
codes: {
ERR_INVALID_ARG_VALUE,
ERR_OPERATION_FAILED,
ERR_INVALID_STATE,
ERR_OPERATION_FAILED,
},
} = require('internal/errors');

View File

@ -18,8 +18,8 @@ const {
const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_STATE,
ERR_INVALID_THIS,
},

View File

@ -93,25 +93,25 @@ const {
kBufferGen,
} = require('internal/stream_base_commons');
const {
ErrnoException,
ExceptionWithHostPort,
NodeAggregateError,
UVExceptionWithHostPort,
codes: {
ERR_INVALID_ADDRESS_FAMILY,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_FD_TYPE,
ERR_INVALID_IP_ADDRESS,
ERR_INVALID_HANDLE_TYPE,
ERR_INVALID_IP_ADDRESS,
ERR_MISSING_ARGS,
ERR_SERVER_ALREADY_LISTEN,
ERR_SERVER_NOT_RUNNING,
ERR_SOCKET_CONNECTION_TIMEOUT,
ERR_SOCKET_CLOSED,
ERR_SOCKET_CLOSED_BEFORE_CONNECTION,
ERR_MISSING_ARGS,
ERR_SOCKET_CONNECTION_TIMEOUT,
},
ErrnoException,
ExceptionWithHostPort,
genericNodeError,
NodeAggregateError,
UVExceptionWithHostPort,
} = require('internal/errors');
const { isUint8Array } = require('internal/util/types');
const { queueMicrotask } = require('internal/process/task_queues');

View File

@ -143,6 +143,7 @@ let debug = require('internal/util/debuglog').debuglog('repl', (fn) => {
debug = fn;
});
const {
ErrorPrepareStackTrace,
codes: {
ERR_CANNOT_WATCH_SIGINT,
ERR_INVALID_REPL_EVAL_CONFIG,
@ -152,7 +153,6 @@ const {
},
isErrorStackTraceLimitWritable,
overrideStackTrace,
ErrorPrepareStackTrace,
} = require('internal/errors');
const { sendInspectorCommand } = require('internal/util/inspector');
const { getOptionValue } = require('internal/options');

View File

@ -29,8 +29,13 @@ const {
const net = require('net');
const { TTY, isTTY } = internalBinding('tty_wrap');
const errors = require('internal/errors');
const { ERR_INVALID_FD, ERR_TTY_INIT_FAILED } = errors.codes;
const {
ErrnoException,
codes: {
ERR_INVALID_FD,
ERR_TTY_INIT_FAILED,
},
} = require('internal/errors');
const {
getColorDepth,
hasColors,
@ -74,7 +79,7 @@ ReadStream.prototype.setRawMode = function(flag) {
flag = !!flag;
const err = this._handle?.setRawMode(flag);
if (err) {
this.emit('error', new errors.ErrnoException(err, 'setRawMode'));
this.emit('error', new ErrnoException(err, 'setRawMode'));
return this;
}
this.isRaw = flag;
@ -129,7 +134,7 @@ WriteStream.prototype._refreshSize = function() {
const winSize = new Array(2);
const err = this._handle.getWindowSize(winSize);
if (err) {
this.emit('error', new errors.ErrnoException(err, 'getWindowSize'));
this.emit('error', new ErrnoException(err, 'getWindowSize'));
return;
}
const { 0: newCols, 1: newRows } = winSize;

View File

@ -48,14 +48,14 @@ const {
} = primordials;
const {
ErrnoException,
ExceptionWithHostPort,
codes: {
ERR_FALSY_VALUE_REJECTION,
ERR_INVALID_ARG_TYPE,
ERR_OUT_OF_RANGE,
},
isErrorStackTraceLimitWritable,
ErrnoException,
ExceptionWithHostPort,
} = require('internal/errors');
const {
format,

View File

@ -9,13 +9,27 @@ common.skipIfEslintMissing();
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/alphabetize-errors');
new RuleTester().run('alphabetize-errors', rule, {
new RuleTester({
parserOptions: { ecmaVersion: 6 },
env: { es6: true }
}).run('alphabetize-errors', rule, {
valid: [
`
{ code: `
E('AAA', 'foo');
E('BBB', 'bar');
E('CCC', 'baz');
`, options: [{ checkErrorDeclarations: true }] },
`
E('AAA', 'foo');
E('CCC', 'baz');
E('BBB', 'bar');
`,
`const {
codes: {
ERR_A,
ERR_B,
},
} = require("internal/errors")`,
],
invalid: [
{
@ -24,7 +38,29 @@ new RuleTester().run('alphabetize-errors', rule, {
E('AAA', 'foo');
E('CCC', 'baz');
`,
options: [{ checkErrorDeclarations: true }],
errors: [{ message: 'Out of ASCIIbetical order - BBB >= AAA', line: 3 }]
},
{
code: `const {
codes: {
ERR_B,
ERR_A,
},
} = require("internal/errors")`,
errors: [{ message: 'Out of ASCIIbetical order - ERR_B >= ERR_A', line: 4 }]
},
{
code: 'const internalErrors = require("internal/errors")',
errors: [{ message: /Use destructuring/ }]
},
{
code: 'const {codes} = require("internal/errors")',
errors: [{ message: /Use destructuring/ }]
},
{
code: 'const {codes:{ERR_A}} = require("internal/errors")',
errors: [{ message: /Use multiline destructuring/ }]
},
]
});

View File

@ -9,12 +9,29 @@ function errorForNode(node) {
return node.expression.arguments[0].value;
}
const requireInternalErrorsSelector =
'VariableDeclarator' +
'[init.type="CallExpression"]' +
'[init.callee.name="require"]' +
'[init.arguments.length=1]' +
'[init.arguments.0.value="internal/errors"]';
const codesSelector = requireInternalErrorsSelector + '>*>Property[key.name="codes"]';
module.exports = {
meta: {
schema: [{
type: 'object',
properties: {
checkErrorDeclarations: { type: 'boolean' },
},
additionalProperties: false,
}],
},
create: function(context) {
let previousNode;
return {
ExpressionStatement: function(node) {
if (!isDefiningError(node)) return;
if (context.options.every((option) => option.checkErrorDeclarations !== true) || !isDefiningError(node)) return;
if (!previousNode) {
previousNode = node;
return;
@ -27,6 +44,32 @@ module.exports = {
context.report({ node, message });
}
},
[requireInternalErrorsSelector](node) {
if (node.id.type !== 'ObjectPattern') {
context.report({ node, message: 'Use destructuring to define error codes used in the file' });
}
},
[codesSelector](node) {
if (node.value.type !== 'ObjectPattern') {
context.report({ node, message: 'Use destructuring to define error codes used in the file' });
return;
}
if (node.value.loc.start.line === node.value.loc.end.line) {
context.report({ node, message: 'Use multiline destructuring for error codes' });
}
},
[requireInternalErrorsSelector + ' Property:not(:first-child)'](node) {
const { properties } = node.parent;
const prev = properties[properties.indexOf(node) - 1].key.name;
const curr = node.key.name;
if (prev >= curr) {
const message = [prefix, prev, opStr, curr].join('');
context.report({ node, message });
}
},
};
},
};