mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
chore(core): optional args for registerErrorClass (#9602)
This commit is contained in:
parent
aa47f8186c
commit
975705a649
4 changed files with 16 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
[WILDCARD]error: Uncaught PermissionDenied: read access to "non-existent", run again with the --allow-read flag
|
[WILDCARD]error: Uncaught PermissionDenied: read access to "non-existent", run again with the --allow-read flag
|
||||||
throw new ErrorClass(res.err.message);
|
throw new ErrorClass(res.err.message, ...args);
|
||||||
^
|
^
|
||||||
at [WILDCARD]
|
at [WILDCARD]
|
||||||
|
|
7
cli/tsc/compiler.d.ts
vendored
7
cli/tsc/compiler.d.ts
vendored
|
@ -37,7 +37,12 @@ declare global {
|
||||||
jsonOpSync<T>(name: string, params: T): any;
|
jsonOpSync<T>(name: string, params: T): any;
|
||||||
ops(): void;
|
ops(): void;
|
||||||
print(msg: string, code?: number): void;
|
print(msg: string, code?: number): void;
|
||||||
registerErrorClass(name: string, Ctor: typeof Error): void;
|
registerErrorClass(
|
||||||
|
name: string,
|
||||||
|
Ctor: typeof Error,
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
...args: any[]
|
||||||
|
): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
type LanguageServerRequest =
|
type LanguageServerRequest =
|
||||||
|
|
14
core/core.js
14
core/core.js
|
@ -174,15 +174,15 @@ SharedQueue Binary Layout
|
||||||
return send(opsCache[opName], control, ...zeroCopy);
|
return send(opsCache[opName], control, ...zeroCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerErrorClass(errorName, className) {
|
function registerErrorClass(errorName, className, args) {
|
||||||
if (typeof errorMap[errorName] !== "undefined") {
|
if (typeof errorMap[errorName] !== "undefined") {
|
||||||
throw new TypeError(`Error class for "${errorName}" already registered`);
|
throw new TypeError(`Error class for "${errorName}" already registered`);
|
||||||
}
|
}
|
||||||
errorMap[errorName] = className;
|
errorMap[errorName] = [className, args ?? []];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getErrorClass(errorName) {
|
function getErrorClassAndArgs(errorName) {
|
||||||
return errorMap[errorName];
|
return errorMap[errorName] ?? [undefined, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns Uint8Array
|
// Returns Uint8Array
|
||||||
|
@ -203,13 +203,13 @@ SharedQueue Binary Layout
|
||||||
if ("ok" in res) {
|
if ("ok" in res) {
|
||||||
return res.ok;
|
return res.ok;
|
||||||
}
|
}
|
||||||
const ErrorClass = getErrorClass(res.err.className);
|
const [ErrorClass, args] = getErrorClassAndArgs(res.err.className);
|
||||||
if (!ErrorClass) {
|
if (!ErrorClass) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unregistered error class: "${res.err.className}"\n ${res.err.message}\n Classes of errors returned from ops should be registered via Deno.core.registerErrorClass().`,
|
`Unregistered error class: "${res.err.className}"\n ${res.err.message}\n Classes of errors returned from ops should be registered via Deno.core.registerErrorClass().`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw new ErrorClass(res.err.message);
|
throw new ErrorClass(res.err.message, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function jsonOpAsync(opName, args = null, ...zeroCopy) {
|
async function jsonOpAsync(opName, args = null, ...zeroCopy) {
|
||||||
|
@ -262,7 +262,7 @@ SharedQueue Binary Layout
|
||||||
close,
|
close,
|
||||||
resources,
|
resources,
|
||||||
registerErrorClass,
|
registerErrorClass,
|
||||||
getErrorClass,
|
getErrorClassAndArgs,
|
||||||
sharedQueueInit: init,
|
sharedQueueInit: init,
|
||||||
// sharedQueue is private but exposed for testing.
|
// sharedQueue is private but exposed for testing.
|
||||||
sharedQueue: {
|
sharedQueue: {
|
||||||
|
|
|
@ -51,13 +51,13 @@
|
||||||
|
|
||||||
function unwrapResponse(res) {
|
function unwrapResponse(res) {
|
||||||
if (res.err != null) {
|
if (res.err != null) {
|
||||||
const ErrorClass = core.getErrorClass(res.err.className);
|
const [ErrorClass, args] = core.getErrorClassAndArgs(res.err.className);
|
||||||
if (!ErrorClass) {
|
if (!ErrorClass) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unregistered error class: "${res.err.className}"\n ${res.err.message}\n Classes of errors returned from ops should be registered via Deno.core.registerErrorClass().`,
|
`Unregistered error class: "${res.err.className}"\n ${res.err.message}\n Classes of errors returned from ops should be registered via Deno.core.registerErrorClass().`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw new ErrorClass(res.err.message);
|
throw new ErrorClass(res.err.message, ...args);
|
||||||
}
|
}
|
||||||
return res.result;
|
return res.result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue