fix: bare raise in ToolUsage._original_tool_calling causes RuntimeError instead of ToolUsageError#6455
Open
rafaelipuente wants to merge 2 commits into
Open
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 (2)
📝 WalkthroughWalkthroughA bare ChangesToolUsageError Fix
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Description
Fixes #6430.
ToolUsage._original_tool_calling()contained a bareraisein thenot isinstance(arguments, dict)branch. A bareraisere-raises the exception currently being handled, but on this path no exception is active (the precedingtry/exceptcompleted normally). If that branch were ever hit withraise_error=True, Python would crash withRuntimeError: No active exception to re-raiseinstead of the intended tool-arguments error.This matters because
_tool_calling()calls this method withraise_error=Trueand relies on catching a meaningful exception to trigger its function-calling/retry fallback.Fix
Replace the bare
raisewith an explicitraise ToolUsageError(...)using the sametool_arguments_errormessage the branch already returns whenraise_error=False, keeping error messaging consistent.Testing
_validate_tool_inputto return a non-dict and asserts_original_tool_calling(..., raise_error=True)raisesToolUsageError(notRuntimeError), and that the non-raise path returns aToolUsageErrorinstance.uv run pytest lib/crewai/tests/tools/test_tool_usage.pypasses (29 tests).ruff check --select PLE0704no longer flags the file; ruff lint/format clean on changed files.(Note: authored with the assistance of an AI coding agent. Please apply the
llm-generatedlabel.)Made with Cursor