Skip to content

Commit

Permalink
refactor: set default for name in ErrorCode.ts (#15699)
Browse files Browse the repository at this point in the history
Co-authored-by: Don Isaac <[email protected]>
  • Loading branch information
DonIsaac and Don Isaac authored Dec 11, 2024
1 parent 24d73e9 commit 78445c5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 65 deletions.
129 changes: 65 additions & 64 deletions src/bun.js/bindings/ErrorCode.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,85 @@
// used by generate-node-errors.ts
type ErrorCodeMapping = Array<
[
/** error.code */
string,
/** Constructor **/
typeof TypeError | typeof RangeError | typeof Error | typeof SyntaxError,
/** error.name */
/** error.name. Defaults to `Constructor.name` (that is, mapping[1].name */
string,
]
>;

export default [
["ABORT_ERR", Error, "AbortError"],
["ERR_CRYPTO_INVALID_DIGEST", TypeError, "TypeError"],
["ERR_ENCODING_INVALID_ENCODED_DATA", TypeError, "TypeError"],
["ERR_INVALID_ARG_TYPE", TypeError, "TypeError"],
["ERR_INVALID_ARG_VALUE", TypeError, "TypeError"],
["ERR_INVALID_PROTOCOL", TypeError, "TypeError"],
["ERR_INVALID_THIS", TypeError, "TypeError"],
["ERR_IPC_CHANNEL_CLOSED", Error, "Error"],
["ERR_IPC_DISCONNECTED", Error, "Error"],
["ERR_MISSING_ARGS", TypeError, "TypeError"],
["ERR_OUT_OF_RANGE", RangeError, "RangeError"],
["ERR_PARSE_ARGS_INVALID_OPTION_VALUE", TypeError, "TypeError"],
["ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL", TypeError, "TypeError"],
["ERR_PARSE_ARGS_UNKNOWN_OPTION", TypeError, "TypeError"],
["ERR_SERVER_NOT_RUNNING", Error, "Error"],
["ERR_SOCKET_BAD_TYPE", TypeError, "TypeError"],
["ERR_STREAM_ALREADY_FINISHED", TypeError, "TypeError"],
["ERR_STREAM_CANNOT_PIPE", TypeError, "TypeError"],
["ERR_STREAM_DESTROYED", TypeError, "TypeError"],
["ERR_STREAM_NULL_VALUES", TypeError, "TypeError"],
["ERR_STREAM_WRITE_AFTER_END", TypeError, "TypeError"],
["ERR_ZLIB_INITIALIZATION_FAILED", Error, "Error"],
["ERR_STRING_TOO_LONG", Error, "Error"],
["ERR_CRYPTO_SCRYPT_INVALID_PARAMETER", Error, "Error"],
["ERR_CRYPTO_INVALID_SCRYPT_PARAMS", RangeError, "RangeError"],
["MODULE_NOT_FOUND", Error, "Error"],
["ERR_ILLEGAL_CONSTRUCTOR", TypeError, "TypeError"],
["ERR_INVALID_URL", TypeError, "TypeError"],
["ERR_BUFFER_TOO_LARGE", RangeError, "RangeError"],
["ERR_BROTLI_INVALID_PARAM", RangeError, "RangeError"],
["ERR_UNKNOWN_ENCODING", TypeError, "TypeError"],
["ERR_INVALID_STATE", Error, "Error"],
["ERR_BUFFER_OUT_OF_BOUNDS", RangeError, "RangeError"],
["ERR_UNKNOWN_SIGNAL", TypeError, "TypeError"],
["ERR_SOCKET_BAD_PORT", RangeError, "RangeError"],
["ERR_CRYPTO_INVALID_DIGEST", TypeError],
["ERR_ENCODING_INVALID_ENCODED_DATA", TypeError],
["ERR_INVALID_ARG_TYPE", TypeError],
["ERR_INVALID_ARG_VALUE", TypeError],
["ERR_INVALID_PROTOCOL", TypeError],
["ERR_INVALID_THIS", TypeError],
["ERR_IPC_CHANNEL_CLOSED", Error],
["ERR_IPC_DISCONNECTED", Error],
["ERR_MISSING_ARGS", TypeError],
["ERR_OUT_OF_RANGE", RangeError],
["ERR_PARSE_ARGS_INVALID_OPTION_VALUE", TypeError],
["ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL", TypeError],
["ERR_PARSE_ARGS_UNKNOWN_OPTION", TypeError],
["ERR_SERVER_NOT_RUNNING", Error],
["ERR_SOCKET_BAD_TYPE", TypeError],
["ERR_STREAM_ALREADY_FINISHED", TypeError],
["ERR_STREAM_CANNOT_PIPE", TypeError],
["ERR_STREAM_DESTROYED", TypeError],
["ERR_STREAM_NULL_VALUES", TypeError],
["ERR_STREAM_WRITE_AFTER_END", TypeError],
["ERR_ZLIB_INITIALIZATION_FAILED", Error],
["ERR_STRING_TOO_LONG", Error],
["ERR_CRYPTO_SCRYPT_INVALID_PARAMETER", Error],
["ERR_CRYPTO_INVALID_SCRYPT_PARAMS", RangeError],
["MODULE_NOT_FOUND", Error],
["ERR_ILLEGAL_CONSTRUCTOR", TypeError],
["ERR_INVALID_URL", TypeError],
["ERR_BUFFER_TOO_LARGE", RangeError],
["ERR_BROTLI_INVALID_PARAM", RangeError],
["ERR_UNKNOWN_ENCODING", TypeError],
["ERR_INVALID_STATE", Error],
["ERR_BUFFER_OUT_OF_BOUNDS", RangeError],
["ERR_UNKNOWN_SIGNAL", TypeError],
["ERR_SOCKET_BAD_PORT", RangeError],
["ERR_STREAM_RELEASE_LOCK", Error, "AbortError"],

// Bun-specific
["ERR_FORMDATA_PARSE_ERROR", TypeError, "TypeError"],
["ERR_BODY_ALREADY_USED", Error, "Error"],
["ERR_STREAM_WRAP", Error, "Error"],
["ERR_BORINGSSL", Error, "Error"],
["ERR_FORMDATA_PARSE_ERROR", TypeError],
["ERR_BODY_ALREADY_USED", Error],
["ERR_STREAM_WRAP", Error],
["ERR_BORINGSSL", Error],

//NET
["ERR_SOCKET_CLOSED_BEFORE_CONNECTION", Error, "Error"],
["ERR_SOCKET_CLOSED", Error, "Error"],
["ERR_SOCKET_CLOSED_BEFORE_CONNECTION", Error],
["ERR_SOCKET_CLOSED", Error],
//HTTP2
["ERR_INVALID_HTTP_TOKEN", TypeError, "TypeError"],
["ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED", TypeError, "TypeError"],
["ERR_HTTP2_SEND_FILE", Error, "Error"],
["ERR_HTTP2_SEND_FILE_NOSEEK", Error, "Error"],
["ERR_INVALID_HTTP_TOKEN", TypeError],
["ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED", TypeError],
["ERR_HTTP2_SEND_FILE", Error],
["ERR_HTTP2_SEND_FILE_NOSEEK", Error],
["ERR_HTTP2_HEADERS_SENT", Error, "ERR_HTTP2_HEADERS_SENT"],
["ERR_HTTP2_INFO_STATUS_NOT_ALLOWED", RangeError, "RangeError"],
["ERR_HTTP2_STATUS_INVALID", RangeError, "RangeError"],
["ERR_HTTP2_INVALID_PSEUDOHEADER", TypeError, "TypeError"],
["ERR_HTTP2_INVALID_HEADER_VALUE", TypeError, "TypeError"],
["ERR_HTTP2_PING_CANCEL", Error, "Error"],
["ERR_HTTP2_STREAM_ERROR", Error, "Error"],
["ERR_HTTP2_INVALID_SINGLE_VALUE_HEADER", TypeError, "TypeError"],
["ERR_HTTP2_SESSION_ERROR", Error, "Error"],
["ERR_HTTP2_INVALID_SESSION", Error, "Error"],
["ERR_HTTP2_INVALID_HEADERS", Error, "Error"],
["ERR_HTTP2_PING_LENGTH", RangeError, "RangeError"],
["ERR_HTTP2_INVALID_STREAM", Error, "Error"],
["ERR_HTTP2_TRAILERS_ALREADY_SENT", Error, "Error"],
["ERR_HTTP2_TRAILERS_NOT_READY", Error, "Error"],
["ERR_HTTP2_PAYLOAD_FORBIDDEN", Error, "Error"],
["ERR_HTTP2_NO_SOCKET_MANIPULATION", Error, "Error"],
["ERR_HTTP2_SOCKET_UNBOUND", Error, "Error"],
["ERR_HTTP2_ERROR", Error, "Error"],
["ERR_HTTP2_OUT_OF_STREAMS", Error, "Error"],
["ERR_HTTP2_INFO_STATUS_NOT_ALLOWED", RangeError],
["ERR_HTTP2_STATUS_INVALID", RangeError],
["ERR_HTTP2_INVALID_PSEUDOHEADER", TypeError],
["ERR_HTTP2_INVALID_HEADER_VALUE", TypeError],
["ERR_HTTP2_PING_CANCEL", Error],
["ERR_HTTP2_STREAM_ERROR", Error],
["ERR_HTTP2_INVALID_SINGLE_VALUE_HEADER", TypeError],
["ERR_HTTP2_SESSION_ERROR", Error],
["ERR_HTTP2_INVALID_SESSION", Error],
["ERR_HTTP2_INVALID_HEADERS", Error],
["ERR_HTTP2_PING_LENGTH", RangeError],
["ERR_HTTP2_INVALID_STREAM", Error],
["ERR_HTTP2_TRAILERS_ALREADY_SENT", Error],
["ERR_HTTP2_TRAILERS_NOT_READY", Error],
["ERR_HTTP2_PAYLOAD_FORBIDDEN", Error],
["ERR_HTTP2_NO_SOCKET_MANIPULATION", Error],
["ERR_HTTP2_SOCKET_UNBOUND", Error],
["ERR_HTTP2_ERROR", Error],
["ERR_HTTP2_OUT_OF_STREAMS", Error],
] as ErrorCodeMapping;
3 changes: 2 additions & 1 deletion src/codegen/generate-node-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub const Error = enum(u8) {

let i = 0;
let listForUsingNamespace = "";
for (const [code, constructor, name] of NodeErrors) {
for (let [code, constructor, name] of NodeErrors) {
if (name == null) name = constructor.name;
enumHeader += ` ${code} = ${i},\n`;
listHeader += ` { JSC::ErrorType::${constructor.name}, "${name}"_s, "${code}"_s },\n`;
zig += ` ${code} = ${i},\n`;
Expand Down

0 comments on commit 78445c5

Please sign in to comment.