mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -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
|
||||
throw new ErrorClass(res.err.message);
|
||||
throw new ErrorClass(res.err.message, ...args);
|
||||
^
|
||||
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;
|
||||
ops(): 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 =
|
||||
|
|
14
core/core.js
14
core/core.js
|
@ -174,15 +174,15 @@ SharedQueue Binary Layout
|
|||
return send(opsCache[opName], control, ...zeroCopy);
|
||||
}
|
||||
|
||||
function registerErrorClass(errorName, className) {
|
||||
function registerErrorClass(errorName, className, args) {
|
||||
if (typeof errorMap[errorName] !== "undefined") {
|
||||
throw new TypeError(`Error class for "${errorName}" already registered`);
|
||||
}
|
||||
errorMap[errorName] = className;
|
||||
errorMap[errorName] = [className, args ?? []];
|
||||
}
|
||||
|
||||
function getErrorClass(errorName) {
|
||||
return errorMap[errorName];
|
||||
function getErrorClassAndArgs(errorName) {
|
||||
return errorMap[errorName] ?? [undefined, []];
|
||||
}
|
||||
|
||||
// Returns Uint8Array
|
||||
|
@ -203,13 +203,13 @@ SharedQueue Binary Layout
|
|||
if ("ok" in res) {
|
||||
return res.ok;
|
||||
}
|
||||
const ErrorClass = getErrorClass(res.err.className);
|
||||
const [ErrorClass, args] = getErrorClassAndArgs(res.err.className);
|
||||
if (!ErrorClass) {
|
||||
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().`,
|
||||
);
|
||||
}
|
||||
throw new ErrorClass(res.err.message);
|
||||
throw new ErrorClass(res.err.message, ...args);
|
||||
}
|
||||
|
||||
async function jsonOpAsync(opName, args = null, ...zeroCopy) {
|
||||
|
@ -262,7 +262,7 @@ SharedQueue Binary Layout
|
|||
close,
|
||||
resources,
|
||||
registerErrorClass,
|
||||
getErrorClass,
|
||||
getErrorClassAndArgs,
|
||||
sharedQueueInit: init,
|
||||
// sharedQueue is private but exposed for testing.
|
||||
sharedQueue: {
|
||||
|
|
|
@ -51,13 +51,13 @@
|
|||
|
||||
function unwrapResponse(res) {
|
||||
if (res.err != null) {
|
||||
const ErrorClass = core.getErrorClass(res.err.className);
|
||||
const [ErrorClass, args] = core.getErrorClassAndArgs(res.err.className);
|
||||
if (!ErrorClass) {
|
||||
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().`,
|
||||
);
|
||||
}
|
||||
throw new ErrorClass(res.err.message);
|
||||
throw new ErrorClass(res.err.message, ...args);
|
||||
}
|
||||
return res.result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue