fix: Preserve error chains across error wrapping boundaries#215
fix: Preserve error chains across error wrapping boundaries#215
Conversation
Six locations wrapped errors without passing { cause: error }, breaking
error chain traversal for debugging and Sentry reporting. Also adds
code property to ExecError for structured errno access.
Warden findings: bf3caddd, 811a555f, 410d3c52, 91113dcf, ebd7c6df, cd7521bb
Severity: medium
Co-Authored-By: Warden <noreply@getsentry.com>
b95174c to
c0ebecb
Compare
|
|
||
| if (result.error) { | ||
| throw new ExecError(command, null, result.error.message, null); | ||
| throw new ExecError(command, null, result.error.message, null, (result.error as NodeJS.ErrnoException).code); |
There was a problem hiding this comment.
ExecError wrapping discards original error chain
The PR claims to fix error chain preservation, but lines 73 and 107 still wrap result.error without passing { cause: result.error }. Additionally, the ExecError constructor (line 6-18) doesn't accept an options parameter to support { cause } - the super() call only passes the message string, not options. This breaks error chain traversal for debugging and Sentry reporting when spawn errors occur.
Verification
Read src/utils/exec.ts and verified: (1) The ExecError constructor at lines 6-18 has signature constructor(command, exitCode, stderr, signal, code?) with no options parameter for cause. (2) The super() call at line 15 passes only the message, not { cause }. (3) Lines 73 and 107 pass result.error.message and the code but not the error itself as cause.
Suggested fix: Update ExecError constructor to accept an options parameter with cause, and pass the original error when throwing
| throw new ExecError(command, null, result.error.message, null, (result.error as NodeJS.ErrnoException).code); | |
| public readonly code?: string, | |
| options?: { cause?: unknown } | |
| super(`Command failed: ${command}\n${details}`, options); |
Identified by Warden find-warden-bugs · QV3-B7G
Six locations wrapped errors without passing
{ cause: error }, breaking error chain traversal for debugging and Sentry reporting. Also adds acodeproperty toExecErrorfor structured errno access.Changes
src/cli/git.ts: Add{ cause: error }to git() wrappersrc/sdk/errors.ts: UpdateWardenAuthenticationErrorto accept{ cause }optionsrc/sdk/auth.ts: Pass cause toWardenAuthenticationErrorthrowssrc/sdk/analyze.ts: Pass cause when rethrowing auth errorssrc/skills/remote.ts: Pass cause toSkillLoaderErrorin execGitsrc/evals/index.ts: Pass cause to file read error wrappersrc/utils/exec.ts: Addcodeproperty toExecError, populate from spawn errorsAutomated fix for Warden findings bf3caddd, 811a555f, 410d3c52, 91113dcf, ebd7c6df, cd7521bb (medium, detected by find-warden-bugs).
Ref #212