Summary
The toError helper in src/api/client.ts (line 6) calls JSON.stringify(err) without a try/catch guard. This can throw if err contains circular references, masking the original error during normalization.
Location
File: src/api/client.ts, lines 4–7
Suggested Fix
function toError(err: unknown): Error {
if (err instanceof Error) return err;
- return new Error(typeof err === "string" ? err : JSON.stringify(err));
+ if (typeof err === "string") return new Error(err);
+ try {
+ return new Error(JSON.stringify(err));
+ } catch {
+ return new Error(String(err));
+ }
}
Context
This was flagged during code review of PR #140 (#140) by @mpiton. The logic is preexisting on main; the PR only reformatted the quote style. The fix was deemed out of scope for that PR and deferred here.
See original review comment: #140 (comment)
Requested by: @mpiton
Summary
The
toErrorhelper insrc/api/client.ts(line 6) callsJSON.stringify(err)without a try/catch guard. This can throw iferrcontains circular references, masking the original error during normalization.Location
File:
src/api/client.ts, lines 4–7Suggested Fix
function toError(err: unknown): Error { if (err instanceof Error) return err; - return new Error(typeof err === "string" ? err : JSON.stringify(err)); + if (typeof err === "string") return new Error(err); + try { + return new Error(JSON.stringify(err)); + } catch { + return new Error(String(err)); + } }Context
This was flagged during code review of PR #140 (#140) by @mpiton. The logic is preexisting on
main; the PR only reformatted the quote style. The fix was deemed out of scope for that PR and deferred here.See original review comment: #140 (comment)
Requested by: @mpiton