fix: bare raise in ToolUsage._original_tool_calling causes RuntimeError instead of ToolUsageError#6455
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 |
|
Same one-line fix as #6486, #6512, #6511, #6499, #6495 — that is now six open PRs (this one included) independently fixing the same bare- |
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