Skip to content

Instantly share code, notes, and snippets.

@NateScarlet
Last active September 29, 2020 10:03
Show Gist options
  • Save NateScarlet/6717763f50f0183f4be8a4587d19a3d0 to your computer and use it in GitHub Desktop.
Save NateScarlet/6717763f50f0183f4be8a4587d19a3d0 to your computer and use it in GitHub Desktop.
import { wrapCallSite } from 'source-map-support';
export default function captureStackTrace(skip = 0): NodeJS.CallSite[] {
const rawPrepareStackTrace = Error.prepareStackTrace;
try {
Error.prepareStackTrace = (_, stack) => stack;
const v: { stack: NodeJS.CallSite[] } = { stack: [] };
Error.captureStackTrace(v);
return v.stack.slice(1 + skip).map(i => wrapCallSite(i));
} finally {
Error.prepareStackTrace = rawPrepareStackTrace;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment