fix: #6430 - Replace bare raise with explicit ToolUsageError in tool_usage.py - #6696
fix: #6430 - Replace bare raise with explicit ToolUsageError in tool_usage.py#6696Diwak4r wants to merge 1 commit into
Conversation
…_original_tool_calling for consistent error handling
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughChangesTool argument error handling
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/crewai/src/crewai/tools/tool_usage.py (1)
846-849: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider explicit exception chaining with
from e.The except block doesn't bind the caught exception, so
raise ToolUsageError(...)only gets implicit chaining (__context__) rather than explicit (__cause__). The PR objectives describe usingraise ToolUsageError(str(e)) from e; binding the exception and chaining explicitly would better preserve the original traceback context and match the stated intent.♻️ Proposed refactor
- except Exception: + except Exception as e: if raise_error: - raise ToolUsageError(f"{I18N_DEFAULT.errors('tool_arguments_error')}") - return ToolUsageError(f"{I18N_DEFAULT.errors('tool_arguments_error')}") + raise ToolUsageError( + f"{I18N_DEFAULT.errors('tool_arguments_error')}" + ) from e + return ToolUsageError(f"{I18N_DEFAULT.errors('tool_arguments_error')}")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/crewai/src/crewai/tools/tool_usage.py` around lines 846 - 849, Update the exception handler around the tool-argument error path to bind the caught exception, then explicitly chain the raised ToolUsageError from that exception when raise_error is true. Preserve the existing localized error message and return behavior for the non-raising branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/crewai/src/crewai/tools/tool_usage.py`:
- Around line 846-849: Update the exception handler around the tool-argument
error path to bind the caught exception, then explicitly chain the raised
ToolUsageError from that exception when raise_error is true. Preserve the
existing localized error message and return behavior for the non-raising branch.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 75e7feb4-b395-4e49-b53b-20a16668c695
📒 Files selected for processing (1)
lib/crewai/src/crewai/tools/tool_usage.py
Summary
Fixes #6430 - Replaces bare
raisestatement with explicitToolUsageErrorinToolUsage._original_tool_callingmethod.Changes
raiseat line ~853 that causedRuntimeError: no active exception to reraisewhenraise_error=Trueand an exception occurred during tool calling.Root Cause
The bare
raisestatement (line ~853) was only valid inside anexceptblock, but was executed outside one. Whenraise_error=Trueand an exception occurred, Python raisedRuntimeErrorinstead of the intendedToolUsageError.Fix
Replaced bare
raisewith explicitraise ToolUsageError(str(e)) from eto match the pattern already used in theraise_error=Falsebranch.Testing
raise_error=Falsebranch