UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

68 lines (67 loc) 2.65 kB
/** * Captures the current process' stack trace. * * Stack traces are often invaluable tools to help diagnose problems, however * their capture is a rather expensive operation, and the stack traces can be * large. Consequently, users are strongly advised to condition capturing stack * traces to specific user opt-in. * * Stack traces will only be captured if the `CDK_DEBUG` environment variable * is set to `'true'` or `1`. * * @param below an optional function starting from which stack frames will be * ignored. Defaults to the `captureStackTrace` function itself. * @param limit and optional upper bound to the number of stack frames to be * captured. If not provided, this defaults to * `Number.MAX_SAFE_INTEGER`, effectively meaning "no limit". * * @returns the captured stack trace, as an array of stack frames. */ export declare function captureStackTrace(below?: Function, limit?: number): string[]; /** * Capture a call stack using `Error.captureStackTrace` * * Modern Nodes have a `util.getCallSites()` API but: * * - it's heavily unstable; and * - source map support works by hijacking `Error.prepareStackTrace`. * * It's easier for us to render a regular stacktrace as a string, have source map support * do the right thing, and then pick it apart, than to try and reconstruct it. */ export declare function captureCallStack(upTo: Function | undefined): CallSite[]; /** * Parse the `error.stack` string into constituent components * * The string looks like this: * * ``` * Error: Some Error message * Potentially spread over multiple lines * at <function> (<file>:<line>:<col>) * at <function> (<file>:<line>:<col>) * at <class>.<function> (<file>:<line>:<col>) * at Object.<anonymous> (<file>:<line>:<col>) * at <function> [as somethingElse] (<file>:<line>:<col>) * at new <constructor> (<file>:<line>:<col>) * at <file>:<line>:<col> * ``` * * `<file>` can be `node:internal/modules/whatever`. */ export declare function parseErrorStack(stack: string): CallSite[]; /** * Renders an array of CallSites nicely, focusing on the user application code * * We detect "Not My Code" using the following heuristics: * * - If there is '/node_modules/' in the file path, we assume the call stack is a library and we skip it. * - If there is 'node:' in the file path, we assume it is NodeJS internals and we skip it. */ export declare function renderCallStackJustMyCode(stack: CallSite[], indent?: boolean): string[]; interface CallSite { functionName: string; fileName: string; sourceLocation: string; } export {};