Skip to content

fix(errors): store cli_path as attribute on CLINotFoundError#989

Open
SHAI-Akshay-Tripathi wants to merge 2 commits into
anthropics:mainfrom
SHAI-Akshay-Tripathi:store-cli-path-on-cli-not-found-error
Open

fix(errors): store cli_path as attribute on CLINotFoundError#989
SHAI-Akshay-Tripathi wants to merge 2 commits into
anthropics:mainfrom
SHAI-Akshay-Tripathi:store-cli-path-on-cli-not-found-error

Conversation

@SHAI-Akshay-Tripathi
Copy link
Copy Markdown

What

CLINotFoundError previously accepted cli_path as a constructor argument
but only used it to format the error message — the path itself was not
retained as an attribute. This PR stores it as self.cli_path.

Why

The other custom error classes in src/claude_agent_sdk/_errors.py all
expose their structured arguments as attributes:

  • ProcessErrorself.exit_code, self.stderr
  • CLIJSONDecodeErrorself.line, self.original_error
  • MessageParseErrorself.data

CLINotFoundError was the lone exception, which meant callers wanting to
react to the missing-path case (e.g. log it, attempt a fallback location,
emit a metric) had to string-parse the message.

Example of what becomes possible:

python except CLINotFoundError as e: if e.cli_path: log.warning("Claude CLI missing at %s", e.cli_path) ​

The message-formatting behaviour is unchanged, so this is fully
backward-compatible.

How to test

bash python -m pytest tests/test_errors.py -v ​

The existing test_cli_not_found_error is extended with one assertion,
and a new test_cli_not_found_error_with_path covers the path-provided
case, mirroring the style of test_process_error.

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.

1 participant