Skip to content

Commit 1ff8d8a

Browse files
committed
fix: handle objects with broken toString in formatError
Property-based testing found that passing an object with toString set to undefined causes String() to throw. Wrap the String() call in a try-catch to handle malformed inputs gracefully. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent af84d53 commit 1ff8d8a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/util.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ export function formatError(error: unknown): string {
22
if (error instanceof Error && error.message.length > 0) {
33
return error.message;
44
}
5-
return String(error);
5+
try {
6+
return String(error);
7+
} catch {
8+
return "[unknown error]";
9+
}
610
}
711

812
export function formatCliOutput(result: { exitCode: number; stdout: string; stderr: string }): string {

0 commit comments

Comments
 (0)