mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
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
This commit is contained in:
parent
b167219bd7
commit
4431dc8f63
10 changed files with 15 additions and 15 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -32,7 +32,7 @@ export function arch(): string {
|
|||
} else if (build.arch == "riscv64gc") {
|
||||
return "riscv64";
|
||||
} else {
|
||||
throw Error("unreachable");
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -311,7 +311,7 @@ export function type(): string {
|
|||
case "openbsd":
|
||||
return "OpenBSD";
|
||||
default:
|
||||
throw Error("unreachable");
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ function regexMatcher(chars) {
|
|||
);
|
||||
return `\\u${a}-\\u${b}`;
|
||||
} else {
|
||||
throw TypeError("unreachable");
|
||||
throw new TypeError("unreachable");
|
||||
}
|
||||
});
|
||||
return ArrayPrototypeJoin(matchers, "");
|
||||
|
|
|
@ -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}".`,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue