MCPcopy Create free account
hub / github.com/lerna/lerna / cleanStack

Function cleanStack

libs/core/src/lib/command/clean-stack.ts:1–12  ·  view source on GitHub ↗
(err: string | Error, className: string)

Source from the content-addressed store, hash-verified

1export function cleanStack(err: string | Error, className: string) {
2 const lines = isErrorWithStack(err) ? err.stack.split("\n") : String(err).split("\n");
3 const cutoff = new RegExp(`^ at ${className}.runCommand .*$`);
4 const relevantIndex = lines.findIndex((line) => cutoff.test(line));
5
6 if (relevantIndex) {
7 return lines.slice(0, relevantIndex).join("\n");
8 }
9
10 // nothing matched, just return original error
11 return err.toString();
12}
13
14function isErrorWithStack(err: Error | string): err is Error & { stack: string } {
15 return (err as Error).stack !== undefined;

Callers 1

constructorMethod · 0.90

Calls 2

isErrorWithStackFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected