summaryrefslogtreecommitdiff
path: root/core/core.js
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2021-02-25 20:06:06 +0100
committerGitHub <noreply@github.com>2021-02-25 20:06:06 +0100
commit975705a64911b0ced8ddf18985b49d86e4f35e51 (patch)
tree8facc49c3ed9479f8e2dc23404997aaf5a11cdd4 /core/core.js
parentaa47f8186cbc068232e23b92a6966be9bd23e4bb (diff)
chore(core): optional args for registerErrorClass (#9602)
Diffstat (limited to 'core/core.js')
-rw-r--r--core/core.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/core.js b/core/core.js
index bda6739a2..fead23907 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: {