mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
update $ERR_INVALID_ARG_VALUE callsites (#16202)
This commit is contained in:
@@ -820,13 +820,6 @@ JSC_DEFINE_HOST_FUNCTION(Bun::jsFunctionMakeErrorWithCode, (JSC::JSGlobalObject
|
||||
JSValue arg0 = callFrame->argument(1);
|
||||
JSValue arg1 = callFrame->argument(2);
|
||||
JSValue arg2 = callFrame->argument(3);
|
||||
|
||||
// TODO: remove this if; this switch case was added but not all the callsites using bare $ERR_INVALID_ARG_VALUE(msg) were updated
|
||||
if (callFrame->argumentCount() == 2 && arg0.isString()) {
|
||||
auto message = arg0.toWTFString(globalObject);
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
return JSC::JSValue::encode(createError(globalObject, error, message));
|
||||
}
|
||||
return JSValue::encode(ERR_INVALID_ARG_TYPE(scope, globalObject, arg0, arg1, arg2));
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ function normalizeSSLMode(value: string): SSLMode {
|
||||
}
|
||||
}
|
||||
|
||||
throw $ERR_INVALID_ARG_VALUE(`Invalid SSL mode: ${value}`);
|
||||
throw $ERR_INVALID_ARG_VALUE("sslmode", value);
|
||||
}
|
||||
|
||||
class Query extends PublicPromise {
|
||||
@@ -454,21 +454,33 @@ function loadOptions(o) {
|
||||
if (idleTimeout != null) {
|
||||
idleTimeout = Number(idleTimeout);
|
||||
if (idleTimeout > 2 ** 31 || idleTimeout < 0 || idleTimeout !== idleTimeout) {
|
||||
throw $ERR_INVALID_ARG_VALUE("idle_timeout must be a non-negative integer less than 2^31");
|
||||
throw $ERR_INVALID_ARG_VALUE(
|
||||
"options.idle_timeout",
|
||||
idleTimeout,
|
||||
"must be a non-negative integer less than 2^31",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (connectionTimeout != null) {
|
||||
connectionTimeout = Number(connectionTimeout);
|
||||
if (connectionTimeout > 2 ** 31 || connectionTimeout < 0 || connectionTimeout !== connectionTimeout) {
|
||||
throw $ERR_INVALID_ARG_VALUE("connection_timeout must be a non-negative integer less than 2^31");
|
||||
throw $ERR_INVALID_ARG_VALUE(
|
||||
"options.connection_timeout",
|
||||
connectionTimeout,
|
||||
"must be a non-negative integer less than 2^31",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxLifetime != null) {
|
||||
maxLifetime = Number(maxLifetime);
|
||||
if (maxLifetime > 2 ** 31 || maxLifetime < 0 || maxLifetime !== maxLifetime) {
|
||||
throw $ERR_INVALID_ARG_VALUE("max_lifetime must be a non-negative integer less than 2^31");
|
||||
throw $ERR_INVALID_ARG_VALUE(
|
||||
"options.max_lifetime",
|
||||
maxLifetime,
|
||||
"must be a non-negative integer less than 2^31",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const { hideFromStack } = require("internal/shared");
|
||||
const { ArrayIsArray } = require("internal/primordials");
|
||||
|
||||
const RegExpPrototypeExec = RegExp.prototype.exec;
|
||||
const ArrayPrototypeIncludes = Array.prototype.includes;
|
||||
const ArrayPrototypeJoin = Array.prototype.join;
|
||||
const ArrayPrototypeMap = Array.prototype.map;
|
||||
const ArrayIsArray = Array.isArray;
|
||||
|
||||
const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
|
||||
/**
|
||||
@@ -28,7 +28,9 @@ const linkValueRegExp = /^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/;
|
||||
function validateLinkHeaderFormat(value, name) {
|
||||
if (typeof value === "undefined" || !RegExpPrototypeExec.$call(linkValueRegExp, value)) {
|
||||
throw $ERR_INVALID_ARG_VALUE(
|
||||
`The arguments ${name} is invalid must be an array or string of format "</styles.css>; rel=preload; as=style"`,
|
||||
name,
|
||||
value,
|
||||
`must be an array or string of format "</styles.css>; rel=preload; as=style"`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -59,7 +61,9 @@ function validateLinkHeaderValue(hints) {
|
||||
}
|
||||
|
||||
throw $ERR_INVALID_ARG_VALUE(
|
||||
`The arguments hints is invalid must be an array or string of format "</styles.css>; rel=preload; as=style"`,
|
||||
"hints",
|
||||
hints,
|
||||
`must be an array or string of format "</styles.css>; rel=preload; as=style"`,
|
||||
);
|
||||
}
|
||||
hideFromStack(validateLinkHeaderValue);
|
||||
|
||||
@@ -349,8 +349,7 @@ class Http2ServerRequest extends Readable {
|
||||
|
||||
set method(method) {
|
||||
validateString(method, "method");
|
||||
if (StringPrototypeTrim(method) === "")
|
||||
throw $ERR_INVALID_ARG_VALUE(`The arguments method is invalid. Received ${method}`);
|
||||
if (StringPrototypeTrim(method) === "") throw $ERR_INVALID_ARG_VALUE("method", method);
|
||||
|
||||
this[kHeaders][HTTP2_HEADER_METHOD] = method;
|
||||
}
|
||||
@@ -642,7 +641,7 @@ class Http2ServerResponse extends Stream {
|
||||
}
|
||||
} else {
|
||||
if (headers.length % 2 !== 0) {
|
||||
throw $ERR_INVALID_ARG_VALUE(`The arguments headers is invalid.`);
|
||||
throw $ERR_INVALID_ARG_VALUE("headers", headers);
|
||||
}
|
||||
|
||||
for (i = 0; i < headers.length; i += 2) {
|
||||
@@ -1637,7 +1636,7 @@ class Http2Stream extends Duplex {
|
||||
const sensitiveNames = {};
|
||||
if (sensitives) {
|
||||
if (!$isJSArray(sensitives)) {
|
||||
throw $ERR_INVALID_ARG_VALUE("The arguments headers[http2.neverIndex] is invalid");
|
||||
throw $ERR_INVALID_ARG_VALUE("headers[http2.neverIndex]", sensitives);
|
||||
}
|
||||
for (let i = 0; i < sensitives.length; i++) {
|
||||
sensitiveNames[sensitives[i]] = true;
|
||||
@@ -2048,7 +2047,7 @@ class ServerHttp2Stream extends Http2Stream {
|
||||
const sensitiveNames = {};
|
||||
if (sensitives) {
|
||||
if (!$isArray(sensitives)) {
|
||||
throw $ERR_INVALID_ARG_VALUE("The arguments headers[http2.neverIndex] is invalid.");
|
||||
throw $ERR_INVALID_ARG_VALUE("headers[http2.neverIndex]", sensitives);
|
||||
}
|
||||
for (let i = 0; i < sensitives.length; i++) {
|
||||
sensitiveNames[sensitives[i]] = true;
|
||||
@@ -2099,7 +2098,7 @@ class ServerHttp2Stream extends Http2Stream {
|
||||
const sensitiveNames = {};
|
||||
if (sensitives) {
|
||||
if (!$isArray(sensitives)) {
|
||||
throw $ERR_INVALID_ARG_VALUE("The arguments headers[http2.neverIndex] is invalid.");
|
||||
throw $ERR_INVALID_ARG_VALUE("headers[http2.neverIndex]", sensitives);
|
||||
}
|
||||
for (let i = 0; i < sensitives.length; i++) {
|
||||
sensitiveNames[sensitives[i]] = true;
|
||||
@@ -3091,7 +3090,7 @@ class ClientHttp2Session extends Http2Session {
|
||||
const sensitiveNames = {};
|
||||
if (sensitives) {
|
||||
if (!$isArray(sensitives)) {
|
||||
throw $ERR_INVALID_ARG_VALUE("The arguments headers[http2.neverIndex] is invalid.");
|
||||
throw $ERR_INVALID_ARG_VALUE("headers[http2.neverIndex]", sensitives);
|
||||
}
|
||||
for (let i = 0; i < sensitives.length; i++) {
|
||||
sensitiveNames[sensitives[i]] = true;
|
||||
|
||||
@@ -2361,7 +2361,7 @@ var require_readable = __commonJS({
|
||||
} = options;
|
||||
|
||||
if (encoding !== undefined && !Buffer.isEncoding(encoding))
|
||||
throw $ERR_INVALID_ARG_VALUE(encoding, "options.encoding");
|
||||
throw $ERR_INVALID_ARG_VALUE("options.encoding", encoding);
|
||||
validateBoolean(objectMode, "options.objectMode");
|
||||
|
||||
// validateBoolean(native, "options.native");
|
||||
|
||||
@@ -133,7 +133,7 @@ function writeHeapSnapshot(path, options) {
|
||||
}
|
||||
|
||||
if (!path) {
|
||||
throw $ERR_INVALID_ARG_VALUE("path must be a non-empty string");
|
||||
throw $ERR_INVALID_ARG_VALUE("path", path, "must be a non-empty string");
|
||||
}
|
||||
} else {
|
||||
path = getDefaultHeapSnapshotPath();
|
||||
|
||||
Reference in New Issue
Block a user