Skip to content

fix: replace bare raise with descriptive ValueError in get_uploader() (#6568)#6588

Open
fazalpsinfo-cmyk wants to merge 1 commit into
crewAIInc:mainfrom
fazalpsinfo-cmyk:fix/bare-raise-6568
Open

fix: replace bare raise with descriptive ValueError in get_uploader() (#6568)#6588
fazalpsinfo-cmyk wants to merge 1 commit into
crewAIInc:mainfrom
fazalpsinfo-cmyk:fix/bare-raise-6568

Conversation

@fazalpsinfo-cmyk

Copy link
Copy Markdown

Description

Two bare raise statements in get_uploader() were outside any exception handler:

  • Line 199: hit when Bedrock is requested without CREWAI_BEDROCK_S3_BUCKET
  • Line 216: hit when an unsupported provider string is passed

This caused RuntimeError: No active exception to re-raise instead of a meaningful error.

Fix

Replaced both bare raise statements with descriptive ValueError messages that clearly indicate the configuration problem.

Closes #6568


Support my work: https://buymeacoffee.com/muhamedfazalps

Two bare `raise` statements were outside any exception handler, causing
RuntimeError instead of a meaningful error. Replaced both with ValueError.

Closes crewAIInc#6568
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Updated get_uploader to replace bare raises with explicit ValueErrors for missing Bedrock S3 configuration and unsupported uploader providers.

Changes

Uploader error handling

Layer / File(s) Summary
Explicit uploader selection errors
lib/crewai-files/src/crewai_files/uploaders/factory.py
Missing Bedrock S3 bucket configuration and unsupported uploader providers now raise descriptive ValueErrors instead of bare raises.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The fix removes bare raises, but it uses ValueError instead of the issue's PermanentUploadError and no regression tests are mentioned. Raise PermanentUploadError for both failing paths and add regression tests for missing Bedrock bucket and unsupported provider inputs.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: replacing bare raises with descriptive errors in get_uploader().
Description check ✅ Passed The description matches the change and explains the bug, fix, and issue linkage.
Out of Scope Changes check ✅ Passed The change appears limited to the uploader factory error paths and stays within the stated objective.
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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@lib/crewai-files/src/crewai_files/uploaders/factory.py`:
- Around line 199-202: The Bedrock S3 uploader factory validates only whether
bucket_name exists in kwargs, allowing None or empty values through. Update the
bucket validation guard in the Bedrock uploader selection logic to reject any
falsy bucket_name value, while preserving acceptance of a valid
environment-provided bucket or non-empty bucket_name kwarg.
- Line 219: Update cleanup_provider_files and FileResolver._get_uploader callers
of get_uploader to match its ValueError contract: replace None-based
unsupported-provider fallback checks with explicit ValueError handling or
intentional propagation, preserving each caller’s expected cleanup/resolution
behavior. Revise the get_uploader docstring to state that unsupported providers
raise ValueError rather than return None.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7b5d5f44-8373-45b0-83dc-96e06d2d73e9

📥 Commits

Reviewing files that changed from the base of the PR and between 69c0308 and 446d04b.

📒 Files selected for processing (1)
  • lib/crewai-files/src/crewai_files/uploaders/factory.py

Comment on lines +199 to +202
raise ValueError(
"Bedrock S3 uploader requires CREWAI_BEDROCK_S3_BUCKET "
"environment variable or bucket_name kwarg"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Validate the bucket value, not only the kwarg’s presence.

When bucket_name=None or bucket_name="" is passed, "bucket_name" in kwargs bypasses this guard, so the factory returns an uploader without a usable bucket and the error is deferred until later use. Check the value instead, e.g. not kwargs.get("bucket_name").

Based on the supplied Bedrock uploader contract, missing bucket values should fail during uploader selection.

🤖 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-files/src/crewai_files/uploaders/factory.py` around lines 199 -
202, The Bedrock S3 uploader factory validates only whether bucket_name exists
in kwargs, allowing None or empty values through. Update the bucket validation
guard in the Bedrock uploader selection logic to reject any falsy bucket_name
value, while preserving acceptance of a valid environment-provided bucket or
non-empty bucket_name kwarg.


logger.debug(f"No file uploader available for provider: {provider}")
raise
raise ValueError(f"Unsupported file uploader provider: {provider}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Update callers for the new exception contract.

cleanup_provider_files and FileResolver._get_uploader currently call get_uploader() and handle an unsupported provider by checking for None. This new exception bypasses those fallback paths and can make cleanup or resolution fail unexpectedly. Update those callers to handle or intentionally propagate ValueError, and revise the docstring that still promises None for unsupported providers.

Based on the supplied downstream snippets, this changes an existing cross-file API contract.

🤖 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-files/src/crewai_files/uploaders/factory.py` at line 219, Update
cleanup_provider_files and FileResolver._get_uploader callers of get_uploader to
match its ValueError contract: replace None-based unsupported-provider fallback
checks with explicit ValueError handling or intentional propagation, preserving
each caller’s expected cleanup/resolution behavior. Revise the get_uploader
docstring to state that unsupported providers raise ValueError rather than
return None.

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 get_uploader() causes RuntimeError instead of PermanentUploadError

1 participant