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

Function logErrorBeforeThrow

packages/cli/src/lib/implementation/global.utils.ts:30–49  ·  view source on GitHub ↗
(
  fn: T,
)

Source from the content-addressed store, hash-verified

28// Related issue: https://github.com/yargs/yargs/issues/2118
29// eslint-disable-next-line @typescript-eslint/no-explicit-any
30export function logErrorBeforeThrow<T extends (...args: any[]) => any>(
31 fn: T,
32): T {
33 // eslint-disable-next-line @typescript-eslint/no-explicit-any
34 return (async (...args: any[]) => {
35 try {
36 return await fn(...args);
37 } catch (error) {
38 if (error instanceof OptionValidationError) {
39 logger.error(error.message);
40 await new Promise(resolve => process.stdout.write('', resolve));
41 yargs().exit(1, error);
42 } else {
43 logger.error(stringifyError(error));
44 await new Promise(resolve => process.stdout.write('', resolve));
45 throw error;
46 }
47 }
48 }) as T;
49}
50
51export function coerceArray(param: string): string[] {
52 return [...new Set(toArray(param).flatMap(f => f.split(',')))];

Callers 2

yargsCliFunction · 0.85

Calls 3

stringifyErrorFunction · 0.90
errorMethod · 0.80
fnFunction · 0.50

Tested by

no test coverage detected