MCPcopy Index your code
hub / github.com/code-pushup/cli / stringifyError

Function stringifyError

packages/utils/src/lib/errors.ts:4–32  ·  view source on GitHub ↗
(
  error: unknown,
  format?: { oneline: boolean },
)

Source from the content-addressed store, hash-verified

2import { UNICODE_ELLIPSIS, truncateMultilineText } from './formatting.js';
3
4export function stringifyError(
5 error: unknown,
6 format?: { oneline: boolean },
7): string {
8 const truncate = (text: string) =>
9 format?.oneline ? truncateMultilineText(text) : text;
10
11 if (error instanceof ZodError) {
12 const formattedError = z.prettifyError(error);
13 if (formattedError.includes('\n')) {
14 if (format?.oneline) {
15 return `${error.name} [${UNICODE_ELLIPSIS}]`;
16 }
17 return `${error.name}:\n${formattedError}\n`;
18 }
19 return `${error.name}: ${formattedError}`;
20 }
21
22 if (error instanceof Error) {
23 if (error.name === 'Error' || error.message.startsWith(error.name)) {
24 return truncate(error.message);
25 }
26 return truncate(`${error.name}: ${error.message}`);
27 }
28 if (typeof error === 'string') {
29 return truncate(error);
30 }
31 return JSON.stringify(error);
32}
33
34/**
35 * Extends an error with a new message and keeps the original as the cause.

Callers 15

parseOptionsFunction · 0.90
collectDiagnosticsFunction · 0.90
getTypeScriptDiagnosticsFunction · 0.90
mergeDiffsFunction · 0.90
loadPortalClientFunction · 0.90
persistReportFunction · 0.90
persistResultFunction · 0.90
loadProjectGraphFunction · 0.90
logErrorBeforeThrowFunction · 0.90
constructorMethod · 0.90
runLighthouseForUrlFunction · 0.90
constructorMethod · 0.90

Calls 1

truncateFunction · 0.85

Tested by

no test coverage detected