summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Bull <irbull@eclipsesource.com>2024-08-28 16:40:37 -0400
committerGitHub <noreply@github.com>2024-08-28 22:40:37 +0200
commit6ccaebcdeae95a82b270ac5bde78b65b37fadb45 (patch)
tree4c50dc3aa74ef6bef2aca4706af8b16213b1e1f2
parent231bdc0aa0c08914735001f5e1261e1808d68190 (diff)
refactor(ext): throw new error instead of throw error (#25272)
To ensure consistency across the codebase, this commit refactors the code in the `ext` folder to use `throw new Error`` instead of `throw` for throwing errors. Fixes https://github.com/denoland/deno/issues/25270
-rw-r--r--ext/fetch/26_fetch.js2
-rw-r--r--ext/http/00_serve.ts8
-rw-r--r--ext/node/polyfills/01_require.js2
-rw-r--r--ext/node/polyfills/02_init.js2
-rw-r--r--ext/node/polyfills/_process/process.ts2
-rw-r--r--ext/node/polyfills/internal/util/comparisons.ts2
-rw-r--r--ext/node/polyfills/os.ts2
-rw-r--r--ext/web/00_infra.js2
-rw-r--r--ext/web/06_streams.js6
-rw-r--r--ext/webidl/00_webidl.js2
10 files changed, 15 insertions, 15 deletions
diff --git a/ext/fetch/26_fetch.js b/ext/fetch/26_fetch.js
index e2809187b..47186fb2d 100644
--- a/ext/fetch/26_fetch.js
+++ b/ext/fetch/26_fetch.js
@@ -145,7 +145,7 @@ async function mainFetch(req, recursive, terminator) {
reqRid = resourceForReadableStream(stream, req.body.length);
}
} else {
- throw TypeError("invalid body");
+ throw new TypeError("invalid body");
}
}
diff --git a/ext/http/00_serve.ts b/ext/http/00_serve.ts
index 02910d580..c8f4e0604 100644
--- a/ext/http/00_serve.ts
+++ b/ext/http/00_serve.ts
@@ -457,7 +457,7 @@ function fastSyncResponseOrStream(
// At this point in the response it needs to be a stream
if (!ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, stream)) {
innerRequest?.close();
- throw TypeError("invalid response");
+ throw new TypeError("invalid response");
}
const resourceBacking = getReadableStreamResourceBacking(stream);
let rid, autoClose;
@@ -506,13 +506,13 @@ function mapToCallback(context, callback, onError) {
// Throwing Error if the handler return value is not a Response class
if (!ObjectPrototypeIsPrototypeOf(ResponsePrototype, response)) {
- throw TypeError(
+ throw new TypeError(
"Return value from serve handler must be a response or a promise resolving to a response",
);
}
if (response.bodyUsed) {
- throw TypeError(
+ throw new TypeError(
"The body of the Response returned from the serve handler has already been consumed.",
);
}
@@ -520,7 +520,7 @@ function mapToCallback(context, callback, onError) {
try {
response = await onError(error);
if (!ObjectPrototypeIsPrototypeOf(ResponsePrototype, response)) {
- throw TypeError(
+ throw new TypeError(
"Return value from onError handler must be a response or a promise resolving to a response",
);
}
diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js
index aec8c55b8..d666b3927 100644
--- a/ext/node/polyfills/01_require.js
+++ b/ext/node/polyfills/01_require.js
@@ -890,7 +890,7 @@ Module._preloadModules = function (requests) {
Module.prototype.load = function (filename) {
if (this.loaded) {
- throw Error("Module already loaded");
+ throw new Error("Module already loaded");
}
// Canonicalize the path so it's not pointing to the symlinked directory
diff --git a/ext/node/polyfills/02_init.js b/ext/node/polyfills/02_init.js
index 870ff12f3..8a4aa8e97 100644
--- a/ext/node/polyfills/02_init.js
+++ b/ext/node/polyfills/02_init.js
@@ -22,7 +22,7 @@ function initialize(args) {
} = args;
if (!warmup) {
if (initialized) {
- throw Error("Node runtime already initialized");
+ throw new Error("Node runtime already initialized");
}
initialized = true;
if (usesLocalNodeModulesDir) {
diff --git a/ext/node/polyfills/_process/process.ts b/ext/node/polyfills/_process/process.ts
index 5abde1cf0..e4b88a11a 100644
--- a/ext/node/polyfills/_process/process.ts
+++ b/ext/node/polyfills/_process/process.ts
@@ -32,7 +32,7 @@ export function arch(): string {
} else if (build.arch == "riscv64gc") {
return "riscv64";
} else {
- throw Error("unreachable");
+ throw new Error("unreachable");
}
}
diff --git a/ext/node/polyfills/internal/util/comparisons.ts b/ext/node/polyfills/internal/util/comparisons.ts
index 65350a813..39e30c69a 100644
--- a/ext/node/polyfills/internal/util/comparisons.ts
+++ b/ext/node/polyfills/internal/util/comparisons.ts
@@ -432,7 +432,7 @@ function isEqualBoxedPrimitive(a: any, b: any): boolean {
}
// assert.fail(`Unknown boxed type ${val1}`);
// return false;
- throw Error(`Unknown boxed type`);
+ throw new Error(`Unknown boxed type`);
}
function getEnumerables(val: any, keys: any) {
diff --git a/ext/node/polyfills/os.ts b/ext/node/polyfills/os.ts
index 1cd466ec2..e47e8679e 100644
--- a/ext/node/polyfills/os.ts
+++ b/ext/node/polyfills/os.ts
@@ -311,7 +311,7 @@ export function type(): string {
case "openbsd":
return "OpenBSD";
default:
- throw Error("unreachable");
+ throw new Error("unreachable");
}
}
diff --git a/ext/web/00_infra.js b/ext/web/00_infra.js
index e42f2cc93..4b241ab5d 100644
--- a/ext/web/00_infra.js
+++ b/ext/web/00_infra.js
@@ -133,7 +133,7 @@ function regexMatcher(chars) {
);
return `\\u${a}-\\u${b}`;
} else {
- throw TypeError("unreachable");
+ throw new TypeError("unreachable");
}
});
return ArrayPrototypeJoin(matchers, "");
diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js
index 130b24783..3da3fe36c 100644
--- a/ext/web/06_streams.js
+++ b/ext/web/06_streams.js
@@ -524,10 +524,10 @@ function dequeueValue(container) {
function enqueueValueWithSize(container, value, size) {
assert(container[_queue] && typeof container[_queueTotalSize] === "number");
if (isNonNegativeNumber(size) === false) {
- throw RangeError("chunk size isn't a positive number");
+ throw new RangeError("chunk size isn't a positive number");
}
if (size === Infinity) {
- throw RangeError("chunk size is invalid");
+ throw new RangeError("chunk size is invalid");
}
container[_queue].enqueue({ value, size });
container[_queueTotalSize] += size;
@@ -543,7 +543,7 @@ function extractHighWaterMark(strategy, defaultHWM) {
}
const highWaterMark = strategy.highWaterMark;
if (NumberIsNaN(highWaterMark) || highWaterMark < 0) {
- throw RangeError(
+ throw new RangeError(
`Expected highWaterMark to be a positive number or Infinity, got "${highWaterMark}".`,
);
}
diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js
index 9ea2200f3..36fc89ce2 100644
--- a/ext/webidl/00_webidl.js
+++ b/ext/webidl/00_webidl.js
@@ -95,7 +95,7 @@ function makeException(ErrorType, message, prefix, context) {
function toNumber(value) {
if (typeof value === "bigint") {
- throw TypeError("Cannot convert a BigInt value to a number");
+ throw new TypeError("Cannot convert a BigInt value to a number");
}
return Number(value);
}