fix(claude_cli): surface stdout in error when CLI exits non-zero
When the claude CLI exits with a non-zero status, the previous error handler only checked stderr. However, the CLI writes its output (including error details) to stdout, especially when invoked with --output-format json. This left the caller with only "exit status 1" and no actionable information. Now includes both stderr and stdout in the error message so the actual failure reason is visible in logs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
19835b2f60
commit
56fb0dc4e3
1 changed files with 10 additions and 2 deletions
|
|
@ -50,10 +50,18 @@ func (p *ClaudeCliProvider) Chat(
|
|||
cmd.Stderr = &stderr
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
if stderrStr := stderr.String(); stderrStr != "" {
|
||||
stderrStr := strings.TrimSpace(stderr.String())
|
||||
stdoutStr := strings.TrimSpace(stdout.String())
|
||||
switch {
|
||||
case stderrStr != "" && stdoutStr != "":
|
||||
return nil, fmt.Errorf("claude cli error: %w\nstderr: %s\nstdout: %s", err, stderrStr, stdoutStr)
|
||||
case stderrStr != "":
|
||||
return nil, fmt.Errorf("claude cli error: %s", stderrStr)
|
||||
case stdoutStr != "":
|
||||
return nil, fmt.Errorf("claude cli error: %w\noutput: %s", err, stdoutStr)
|
||||
default:
|
||||
return nil, fmt.Errorf("claude cli error: %w", err)
|
||||
}
|
||||
return nil, fmt.Errorf("claude cli error: %w", err)
|
||||
}
|
||||
|
||||
return p.parseClaudeCliResponse(stdout.String())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue