Skip to content

Commit db536ae

Browse files
Handle all CLI errors instead of rethrowing
1 parent 94de5e1 commit db536ae

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/cli/errors.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class CLIError extends Error {
1616

1717
/**
1818
* Wraps a CLI action / handler function with error handling that catches
19-
* CLIError, prints it to the console, then exits. Other errors are rethrown.
19+
* errors, prints them to the console, then exits.
2020
* @param fn - Action handler
2121
* @returns Wrapped handler
2222
*/
@@ -33,7 +33,13 @@ export function withErrorHandling<T extends unknown[]>(
3333
// eslint-disable-next-line unicorn/no-process-exit
3434
process.exit(1);
3535
}
36-
throw error;
36+
const message = error instanceof Error ? error.message : String(error);
37+
consola.error(`Unexpected error: ${message}`);
38+
if (error instanceof Error && error.stack) {
39+
consola.debug(error.stack);
40+
}
41+
// eslint-disable-next-line unicorn/no-process-exit
42+
process.exit(1);
3743
}
3844
};
3945
}

0 commit comments

Comments
 (0)