review this PR
- User
review this PR
Assistant· claude-opus-4-7
PR #963 Review —
feat: classify Claude CLI errors into actionable user messagesOverview
Replaces opaque
failed to parse summary JSONerrors with typed*claudecode.ClaudeError(Auth / RateLimit / Config / CLIMissing / Unknown). Wireserrors.Asfromclaudecode.GenerateText→summarize.Generate→explain.formatCheckpointSummaryError. Adds settings groundwork (summary_timeout_seconds) used by stacked follow-up. +866 / −37 with strong test coverage.Direction is correct. Comments + negative-assertion tests are unusually disciplined.
Findings
Real concerns
-
error.go:38-46vsexplain.go:650-664renderExitCode<0differently.Error()printskind=unknown, exit=-1.formatClaudeErrorSuffixrenders the same condition as"abnormal termination — no exit code captured". The latter is the intended UX (covered byTestFormatCheckpointSummaryError_Unknown); the former leaks through anywhere callers logerr.Error()directly. RecommendError()mirror the same<0 → "abnormal"rule, or share one helper. -
classifyStderrErrortruncates before phrase match (error.go:95-100). If"Invalid API key"appears past byte 500, classification falls through toUnknown. Match phrase first, then truncate the storedMessage. -
No test for envelope-is-error + non-zero exit (
generate.go:58-69).TestGenerateText_EnvelopeErrorReturnsClaudeErrorrunsprintf(exit 0). The branch that capturesexitErr.ExitCode()on the envelope-error path is unexercised — exactly the OOM/SIGKILL-with-partial-stdout scenario this PR cites. -
summary_timeout_secondsshipped without effect. Settings field + accessor + test merge today, generate path doesn't read it (PR description acknowledges). Risk: users set it after release and report "summary_timeout_seconds is ignored." Either gate behind the follow-up PR or document as a no-op in the field comment + CHANGELOG.
Minor
-
generate.go:72-77ctx checks discarderr. When is non-nil for any reason (parent timeout, sibling cancel) we return the bare sentinel and drop 's actual error (e.g., ). Comment acknowledges the trade-off; consider attaching via to the sentinel for log-side debuggability without changing user-facing routing (since still matches).
-
- User
[P2] Preserve stdout/exec detail for non-envelope Claude failures — /Users/gtrrz-victor/wks/cli/cli/cmd/entire/cli/agent/claudecode/generate.go:81-86 When cmd.Run() fails and stdout does not contain a parseable is_error envelope, this branch now classifies the failure from stderr alone. The previous helper fell back to stdout and finally err.Error(), so cases like a broken/incompatible claude binary or a non-zero exit that reports its error on stdout now collapse into ClaudeErrorUnknown with an empty message, and entire explain --generate ends up telling the user there is “no diagnostic detail”. Please keep stdout and the original exec error as fallbacks here so these failures stay actionable.
Assistant· claude-opus-4-7
Will fix. Plan: at exec-failure path, prefer stderr → stdout → err.Error() so message non-empty + auth-phrase check still scans whichever source had detail.
- User
[Request interrupted by user for tool use]
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.