Skip to content

fix: capture stderr in ProcessError for better debugging (#641)#658

Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/capture-stderr-for-process-error
Open

fix: capture stderr in ProcessError for better debugging (#641)#658
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/capture-stderr-for-process-error

Conversation

@MaxwellCalkin
Copy link

Summary

Fixes #641ProcessError now includes the actual CLI stderr output instead of a generic placeholder message.

Problem: When the CLI subprocess exits with a non-zero exit code, ProcessError was raised with stderr="Check stderr output for details" — a hardcoded string that provides no useful debugging information. Worse, stderr was only piped at all when the user explicitly provided a stderr callback or enabled debug mode, so in the common case the real error output was lost entirely.

Root cause in subprocess_cli.py:

  1. stderr was conditionally piped (only with callback or debug mode)
  2. When piped, stderr was consumed by _handle_stderr() for callbacks but never retained
  3. ProcessError always used a hardcoded placeholder string

Fix:

  • Always pipe stderr from the subprocess so error output is available regardless of user configuration
  • Buffer all stderr lines in self._stderr_buffer (in addition to invoking existing user callbacks / debug output)
  • Use the captured buffer when constructing ProcessError, so callers see the real CLI error
  • Reset the buffer in close() to prevent memory leaks

Before

ProcessError: Command failed with exit code 1 (exit code: 1)
Error output: Check stderr output for details

After

ProcessError: Command failed with exit code 1 (exit code: 1)
Error output: Error: No conversation found with session ID ab2c985b

Test plan

  • ruff check passes — no lint issues
  • mypy passes — no type errors
  • Existing test suite passes (no behavioral changes to happy path)
  • Manual test: trigger a CLI error (e.g., resume non-existent session) and verify ProcessError.stderr contains the real error message

🤖 Generated with Claude Code

)

Previously, stderr was only piped when the user provided a callback or
enabled debug mode. When the CLI process exited with an error,
ProcessError was raised with the generic message "Check stderr output
for details" instead of the actual error text.

This change:
- Always pipes stderr from the subprocess
- Buffers all stderr lines in _stderr_buffer alongside existing callbacks
- Uses the captured stderr content in ProcessError when the process fails
- Resets the buffer on close() to prevent memory leaks

Fixes anthropics#641

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@c3-rambandi
Copy link

amazing, let's merge this asap

@b657bm7n98-hub
Copy link

Is this the same as #529?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ProcessError loses real CLI error message during initialize()

3 participants