diff --git a/cli/tests/059_fs_relative_path_perm.ts.out b/cli/tests/059_fs_relative_path_perm.ts.out index 92d6b5966c..833db78bf9 100644 --- a/cli/tests/059_fs_relative_path_perm.ts.out +++ b/cli/tests/059_fs_relative_path_perm.ts.out @@ -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] diff --git a/cli/tsc/compiler.d.ts b/cli/tsc/compiler.d.ts index 7d102eb564..d37b56c060 100644 --- a/cli/tsc/compiler.d.ts +++ b/cli/tsc/compiler.d.ts @@ -37,7 +37,12 @@ declare global { jsonOpSync(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 = diff --git a/core/core.js b/core/core.js index bda6739a2a..fead239075 100644 --- a/core/core.js +++ b/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: { diff --git a/runtime/js/10_dispatch_minimal.js b/runtime/js/10_dispatch_minimal.js index 4d6af6fc37..e74f8c3934 100644 --- a/runtime/js/10_dispatch_minimal.js +++ b/runtime/js/10_dispatch_minimal.js @@ -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; }