summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-10-07 18:39:27 +0200
committerGitHub <noreply@github.com>2021-10-07 18:39:27 +0200
commit370c27e09a63ca36f0e0aba8bef6b10f4484d70d (patch)
tree631924fc770337900bcd0d6abd5943f13a241f42
parentab2e0a465e4eafe4de2cc6ac7ef61d1655db4c2d (diff)
feat(core): cleaner opcall stack traces (#12358)
-rw-r--r--cli/tests/unit/opcall_test.ts11
-rw-r--r--core/01_core.js13
2 files changed, 17 insertions, 7 deletions
diff --git a/cli/tests/unit/opcall_test.ts b/cli/tests/unit/opcall_test.ts
index 9c0d39d2e..7e3685320 100644
--- a/cli/tests/unit/opcall_test.ts
+++ b/cli/tests/unit/opcall_test.ts
@@ -1,4 +1,9 @@
-import { assertStringIncludes, unitTest, unreachable } from "./test_util.ts";
+import {
+ assert,
+ assertStringIncludes,
+ unitTest,
+ unreachable,
+} from "./test_util.ts";
unitTest(async function sendAsyncStackTrace() {
const buf = new Uint8Array(10);
@@ -11,6 +16,10 @@ unitTest(async function sendAsyncStackTrace() {
console.log(s);
assertStringIncludes(s, "opcall_test.ts");
assertStringIncludes(s, "read");
+ assert(
+ !s.includes("deno:core"),
+ "opcall stack traces should NOT include deno:core internals such as unwrapOpResult",
+ );
}
});
diff --git a/core/01_core.js b/core/01_core.js
index 5af352340..e1b0529f7 100644
--- a/core/01_core.js
+++ b/core/01_core.js
@@ -12,6 +12,7 @@
Map,
Array,
ArrayPrototypeFill,
+ ErrorCaptureStackTrace,
Promise,
ObjectFreeze,
ObjectFromEntries,
@@ -113,12 +114,12 @@
if (res?.$err_class_name) {
const className = res.$err_class_name;
const errorBuilder = errorMap[className];
- if (!errorBuilder) {
- throw new Error(
- `Unregistered error class: "${className}"\n ${res.message}\n Classes of errors returned from ops should be registered via Deno.core.registerErrorClass().`,
- );
- }
- throw errorBuilder(res.message);
+ const err = errorBuilder ? errorBuilder(res.message) : new Error(
+ `Unregistered error class: "${className}"\n ${res.message}\n Classes of errors returned from ops should be registered via Deno.core.registerErrorClass().`,
+ );
+ // Strip unwrapOpResult() and errorBuilder() calls from stack trace
+ ErrorCaptureStackTrace(err, unwrapOpResult);
+ throw err;
}
return res;
}