Skip to content

Commit

Permalink
lib: enforce ASCII order in error code imports
Browse files Browse the repository at this point in the history
PR-URL: #52625
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
aduh95 authored Apr 23, 2024
1 parent ff82606 commit 231548b
Show file tree
Hide file tree
Showing 59 changed files with 268 additions and 168 deletions.
1 change: 1 addition & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
22 changes: 11 additions & 11 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 18 additions & 16 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 7 additions & 8 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 16 additions & 18 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -97,11 +100,6 @@ function lazyLoadCluster() {
return _cluster;
}

const {
ErrnoException,
ExceptionWithHostPort,
} = errors;

function Socket(type, listener) {
FunctionPrototypeCall(EventEmitter, this);
let lookup;
Expand Down
2 changes: 1 addition & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/assert/calltracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/crypto/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/crypto/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ const {
const normalizeHashName = require('internal/crypto/hashnames');

const {
hideStackFrames,
codes: {
ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED,
ERR_CRYPTO_ENGINE_UNKNOWN,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_OUT_OF_RANGE,
},
hideStackFrames,
} = require('internal/errors');

const {
Expand Down
7 changes: 3 additions & 4 deletions lib/internal/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ 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 {
isInt32,
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.

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/dns/callback_resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const {
} = primordials;

const {
DNSException,
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
},
DNSException,
} = require('internal/errors');

const {
Expand Down
Loading

0 comments on commit 231548b

Please sign in to comment.