fix(tools): replace bare raise with ToolUsageError in _original_tool_calling#6431
Open
molinto wants to merge 2 commits into
Open
fix(tools): replace bare raise with ToolUsageError in _original_tool_calling#6431molinto wants to merge 2 commits into
molinto wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
👮 Files not reviewed due to content moderation or server errors (3)
📝 Walkthrough
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6430
Problem
ToolUsage._original_tool_calling()contains a bareraiseoutside anyexceptblock:A bare
raisere-raises the exception currently being handled. On this path no exception is active (the precedingtry/exceptcompleted normally), so if_validate_tool_inputever returns a non-dict, Python raisesRuntimeError: No active exception to re-raiseinstead of the intended tool-arguments error.Today
_validate_tool_inputalways returns a dict or raises, so the branch is a latent landmine rather than a hot path — but_tool_calling()calls this withraise_error=Trueand relies on catching a meaningful exception to trigger its fallback, so any future change or subclass of_validate_tool_inputwould surface this as a confusingRuntimeError.ruff check --select PLE0704also flags this line. (It flags one more bareraiseincrewai/agent/core.py:660; that one is only ever reached from within an exception context via_handle_execution_error, so it behaves correctly at runtime — left untouched here.)Fix
Raise
ToolUsageError(anExceptionsubclass) with the same i18n message the non-raising branch returns, keeping both branches consistent.Tests
Added a regression test in
lib/crewai/tests/tools/test_tool_usage.pythat forces_validate_tool_inputto return a non-dict and assertsToolUsageErroris raised (previously:RuntimeError). Verified failing-without / passing-with the fix.ruffclean on the touched file.Note for maintainers
This contribution was made with AI assistance. Per CONTRIBUTING.md the
llm-generatedlabel is required — I don't have triage permission to set it, so could a maintainer please add it?