Skip to content

fix(tools): raise ToolUsageError instead of bare raise in _original_tool_calling#6511

Open
Aakash326 wants to merge 1 commit into
crewAIInc:mainfrom
Aakash326:fix/tool-usage-bare-raise
Open

fix(tools): raise ToolUsageError instead of bare raise in _original_tool_calling#6511
Aakash326 wants to merge 1 commit into
crewAIInc:mainfrom
Aakash326:fix/tool-usage-bare-raise

Conversation

@Aakash326

Copy link
Copy Markdown

Fixes #6430.

The bare raise in the non-dict-arguments branch of _original_tool_calling
had no active exception to re-raise, so Python raised
RuntimeError: No active exception to re-raise instead of a meaningful
ToolUsageError. Replaced it with an explicit raise ToolUsageError(...)
matching the sibling return statement and the pattern used elsewhere in
this method.

Added regression test covering both raise_error=True and raise_error=False
paths.

…ool_calling

Fixes crewAIInc#6430. The bare 'raise' in the non-dict-arguments branch of
_original_tool_calling had no active exception to re-raise, so Python
raised 'RuntimeError: No active exception to re-raise' instead of a
meaningful ToolUsageError. Replaced it with an explicit
'raise ToolUsageError(...)' matching the sibling return statement and
the pattern used elsewhere in this method.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9f3b20a3-8be6-4f93-99eb-3f8d8887e2de

📥 Commits

Reviewing files that changed from the base of the PR and between 7baf8f9 and 0bb488d.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/tools/tool_usage.py
  • lib/crewai/tests/tools/test_tool_usage.py

📝 Walkthrough

Walkthrough

Changes

Tool argument error handling

Layer / File(s) Summary
Normalize invalid argument errors
lib/crewai/src/crewai/tools/tool_usage.py, lib/crewai/tests/tools/test_tool_usage.py
_original_tool_calling raises ToolUsageError for non-dictionary arguments when requested, and regression tests verify both raised and returned errors use the localized message.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix in _original_tool_calling and matches the change set.
Description check ✅ Passed The description accurately explains the bug fix and the added regression test.
Linked Issues check ✅ Passed The change replaces the bare raise with ToolUsageError and preserves the non-raise_error path as required by #6430.
Out of Scope Changes check ✅ Passed The PR stays focused on the reported bug fix and its regression test, with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

[BUG] Bare raise in ToolUsage._original_tool_calling causes RuntimeError instead of ToolUsageError

1 participant