Skip to content

fix: replace bare raise outside except block with explicit ToolUsageError#6512

Open
gautamkishore wants to merge 2 commits into
crewAIInc:mainfrom
gautamkishore:fix/6430-bare-raise
Open

fix: replace bare raise outside except block with explicit ToolUsageError#6512
gautamkishore wants to merge 2 commits into
crewAIInc:mainfrom
gautamkishore:fix/6430-bare-raise

Conversation

@gautamkishore

Copy link
Copy Markdown

In _original_tool_calling, the bare raise on the non-dict branch (line 853) is outside any active exception handler — Python raises RuntimeError: No active exception to re-raise instead of the intended ToolUsageError.

The other bare raise (line 848) is inside the except Exception: block and is correct.

Fixes #6430

…rror

In _original_tool_calling, a bare raise on the non-dict branch is outside any active exception handler. Python raises RuntimeError instead of ToolUsageError.

Fixes crewAIInc#6430
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@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: 7099eeb3-7e09-4dcd-891b-9e6b31b9caca

📥 Commits

Reviewing files that changed from the base of the PR and between 697ca56 and c6daca1.

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

📝 Walkthrough

Walkthrough

The non-dictionary argument branch in ToolUsage._original_tool_calling now raises ToolUsageError with the localized tool-arguments message when raise_error=True; the non-raising return behavior remains unchanged.

Changes

Tool usage error handling

Layer / File(s) Summary
Non-dictionary argument error
lib/crewai/src/crewai/tools/tool_usage.py, lib/crewai/tests/tools/test_tool_usage.py
_original_tool_calling now raises ToolUsageError instead of re-raising an inactive exception, with a regression test covering invalid non-dictionary input.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: replacing the invalid bare raise with ToolUsageError in ToolUsage._original_tool_calling.
Description check ✅ Passed The description matches the code change and explains the RuntimeError bug being fixed in the non-dict argument branch.
Linked Issues check ✅ Passed The PR satisfies #6430 by raising ToolUsageError with the existing i18n message and adding a regression test.
Out of Scope Changes check ✅ Passed The changes stay focused on the reported bug and its regression test; no unrelated code changes are introduced.
✨ 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.

…c#6430)

Covers the _original_tool_calling non-dict branch: with raise_error=True it must raise ToolUsageError, not RuntimeError from a bare raise outside an except block.

@ErenAta16 ErenAta16 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same one-line fix as #6486, #6512, #6511, #6499 — this is one of five open PRs (added this one to the tally) independently fixing the same bare-raise-outside-except bug in _original_tool_calling. Reproduced the bug standalone: the bare raise here raises RuntimeError: No active exception to reraise rather than the intended ToolUsageError, since it is outside any except block. This PR's fix is correct and equivalent to the others. Left a fuller comparison on #6486, which constructs the error once and reuses it for both branches rather than twice — noting the duplication here so only one lands.

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

2 participants