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
231bdc0aa0
commit
6ccaebcdea
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);
|
reqRid = resourceForReadableStream(stream, req.body.length);
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
// At this point in the response it needs to be a stream
|
||||||
if (!ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, stream)) {
|
if (!ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, stream)) {
|
||||||
innerRequest?.close();
|
innerRequest?.close();
|
||||||
throw TypeError("invalid response");
|
throw new TypeError("invalid response");
|
||||||
}
|
}
|
||||||
const resourceBacking = getReadableStreamResourceBacking(stream);
|
const resourceBacking = getReadableStreamResourceBacking(stream);
|
||||||
let rid, autoClose;
|
let rid, autoClose;
|
||||||
|
@ -506,13 +506,13 @@ function mapToCallback(context, callback, onError) {
|
||||||
|
|
||||||
// Throwing Error if the handler return value is not a Response class
|
// Throwing Error if the handler return value is not a Response class
|
||||||
if (!ObjectPrototypeIsPrototypeOf(ResponsePrototype, response)) {
|
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",
|
"Return value from serve handler must be a response or a promise resolving to a response",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.bodyUsed) {
|
if (response.bodyUsed) {
|
||||||
throw TypeError(
|
throw new TypeError(
|
||||||
"The body of the Response returned from the serve handler has already been consumed.",
|
"The body of the Response returned from the serve handler has already been consumed.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -520,7 +520,7 @@ function mapToCallback(context, callback, onError) {
|
||||||
try {
|
try {
|
||||||
response = await onError(error);
|
response = await onError(error);
|
||||||
if (!ObjectPrototypeIsPrototypeOf(ResponsePrototype, response)) {
|
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",
|
"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) {
|
Module.prototype.load = function (filename) {
|
||||||
if (this.loaded) {
|
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
|
// Canonicalize the path so it's not pointing to the symlinked directory
|
||||||
|
|
|
@ -22,7 +22,7 @@ function initialize(args) {
|
||||||
} = args;
|
} = args;
|
||||||
if (!warmup) {
|
if (!warmup) {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
throw Error("Node runtime already initialized");
|
throw new Error("Node runtime already initialized");
|
||||||
}
|
}
|
||||||
initialized = true;
|
initialized = true;
|
||||||
if (usesLocalNodeModulesDir) {
|
if (usesLocalNodeModulesDir) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ export function arch(): string {
|
||||||
} else if (build.arch == "riscv64gc") {
|
} else if (build.arch == "riscv64gc") {
|
||||||
return "riscv64";
|
return "riscv64";
|
||||||
} else {
|
} 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}`);
|
// assert.fail(`Unknown boxed type ${val1}`);
|
||||||
// return false;
|
// return false;
|
||||||
throw Error(`Unknown boxed type`);
|
throw new Error(`Unknown boxed type`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEnumerables(val: any, keys: any) {
|
function getEnumerables(val: any, keys: any) {
|
||||||
|
|
|
@ -311,7 +311,7 @@ export function type(): string {
|
||||||
case "openbsd":
|
case "openbsd":
|
||||||
return "OpenBSD";
|
return "OpenBSD";
|
||||||
default:
|
default:
|
||||||
throw Error("unreachable");
|
throw new Error("unreachable");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ function regexMatcher(chars) {
|
||||||
);
|
);
|
||||||
return `\\u${a}-\\u${b}`;
|
return `\\u${a}-\\u${b}`;
|
||||||
} else {
|
} else {
|
||||||
throw TypeError("unreachable");
|
throw new TypeError("unreachable");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return ArrayPrototypeJoin(matchers, "");
|
return ArrayPrototypeJoin(matchers, "");
|
||||||
|
|
|
@ -524,10 +524,10 @@ function dequeueValue(container) {
|
||||||
function enqueueValueWithSize(container, value, size) {
|
function enqueueValueWithSize(container, value, size) {
|
||||||
assert(container[_queue] && typeof container[_queueTotalSize] === "number");
|
assert(container[_queue] && typeof container[_queueTotalSize] === "number");
|
||||||
if (isNonNegativeNumber(size) === false) {
|
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) {
|
if (size === Infinity) {
|
||||||
throw RangeError("chunk size is invalid");
|
throw new RangeError("chunk size is invalid");
|
||||||
}
|
}
|
||||||
container[_queue].enqueue({ value, size });
|
container[_queue].enqueue({ value, size });
|
||||||
container[_queueTotalSize] += size;
|
container[_queueTotalSize] += size;
|
||||||
|
@ -543,7 +543,7 @@ function extractHighWaterMark(strategy, defaultHWM) {
|
||||||
}
|
}
|
||||||
const highWaterMark = strategy.highWaterMark;
|
const highWaterMark = strategy.highWaterMark;
|
||||||
if (NumberIsNaN(highWaterMark) || highWaterMark < 0) {
|
if (NumberIsNaN(highWaterMark) || highWaterMark < 0) {
|
||||||
throw RangeError(
|
throw new RangeError(
|
||||||
`Expected highWaterMark to be a positive number or Infinity, got "${highWaterMark}".`,
|
`Expected highWaterMark to be a positive number or Infinity, got "${highWaterMark}".`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ function makeException(ErrorType, message, prefix, context) {
|
||||||
|
|
||||||
function toNumber(value) {
|
function toNumber(value) {
|
||||||
if (typeof value === "bigint") {
|
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);
|
return Number(value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue