summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/hide_stack_frames.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/internal/hide_stack_frames.ts')
-rw-r--r--ext/node/polyfills/internal/hide_stack_frames.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/node/polyfills/internal/hide_stack_frames.ts b/ext/node/polyfills/internal/hide_stack_frames.ts
new file mode 100644
index 000000000..e1a6e4c27
--- /dev/null
+++ b/ext/node/polyfills/internal/hide_stack_frames.ts
@@ -0,0 +1,16 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+// deno-lint-ignore no-explicit-any
+type GenericFunction = (...args: any[]) => any;
+
+/** This function removes unnecessary frames from Node.js core errors. */
+export function hideStackFrames<T extends GenericFunction = GenericFunction>(
+ fn: T,
+): T {
+ // We rename the functions that will be hidden to cut off the stacktrace
+ // at the outermost one.
+ const hidden = "__node_internal_" + fn.name;
+ Object.defineProperty(fn, "name", { value: hidden });
+
+ return fn;
+}