Skip to content

Replace assert with proper error handling in tool execution loop#70

Open
hobostay wants to merge 1 commit into
antoinezambelli:mainfrom
hobostay:fix/replace-assert-runner
Open

Replace assert with proper error handling in tool execution loop#70
hobostay wants to merge 1 commit into
antoinezambelli:mainfrom
hobostay:fix/replace-assert-runner

Conversation

@hobostay
Copy link
Copy Markdown

Summary

  • assert last_error is not None was used as a runtime guard in the tool execution error path
  • Python strips assert statements when run with -O (optimized mode), which some deployments use
  • If the invariant were violated under -O, last_error[0] would raise an opaque TypeError instead of a meaningful error

Replace with an explicit if-check that raises ToolExecutionError with a clear diagnostic message.

Test plan

  • Verify tool execution errors still propagate correctly
  • Verify behavior under python -O is correct
  • Run existing test suite

🤖 Generated with Claude Code

`assert last_error is not None` was used as a runtime guard, but
asserts are stripped when Python runs with -O (optimized mode). If the
invariant were ever violated under -O, `last_error[0]` would raise an
opaque TypeError instead of a meaningful error.

Replace with an explicit if-check that raises ToolExecutionError with
a clear diagnostic message if last_error is unexpectedly None.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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