Skip to content

fix: replace bare raise in get_uploader with PermanentUploadError#6614

Open
Diwak4r wants to merge 1 commit into
crewAIInc:mainfrom
Diwak4r:fix/bare-raise-uploader-factory
Open

fix: replace bare raise in get_uploader with PermanentUploadError#6614
Diwak4r wants to merge 1 commit into
crewAIInc:mainfrom
Diwak4r:fix/bare-raise-uploader-factory

Conversation

@Diwak4r

@Diwak4r Diwak4r commented Jul 22, 2026

Copy link
Copy Markdown

Fixes a bug where two bare raise statements in get_uploader() (lib/crewai-files/src/crewai_files/uploaders/factory.py:199,216) were not inside any exception handler, causing RuntimeError: No active exception to re-raise instead of a meaningful error.

  • Line 199 — Bedrock S3 uploader requested without CREWAI_BEDROCK_S3_BUCKET set
  • Line 216 — Unknown/unsupported provider string

Both now raise PermanentUploadError from crewai_files.processing.exceptions, matching the existing pattern in the codebase.

Closes #6568

…adError

Two bare `raise` statements in get_uploader() were outside any exception
handler, causing RuntimeError: No active exception to re-raise instead
of a meaningful exception. Replaced with PermanentUploadError and
descriptive messages.

- Line 199 (Bedrock S3 bucket not configured)
- Line 216 (unknown provider)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 22, 2026 13:41
@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The uploader factory replaces bare raises with descriptive PermanentUploadError exceptions for missing Bedrock configuration and unsupported providers. New tests cover both errors and verify valid provider handling.

Changes

Uploader factory errors

Layer / File(s) Summary
Factory error handling and regression coverage
lib/crewai-files/src/crewai_files/uploaders/factory.py, lib/crewai-files/tests/test_uploader_factory.py
get_uploader raises PermanentUploadError with configuration or provider details, and tests validate the error paths and supported providers.

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: replacing bare raises in get_uploader with PermanentUploadError.
Description check ✅ Passed The description matches the code changes and explains the bug fix and affected cases.
Linked Issues check ✅ Passed The PR addresses #6568 by replacing both bare raises with PermanentUploadError and adding regression tests.
Out of Scope Changes check ✅ Passed The changes stay focused on the uploader factory fix and its tests, with no unrelated additions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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

🧹 Nitpick comments (1)
lib/crewai-files/src/crewai_files/uploaders/factory.py (1)

220-222: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Update the get_uploader() docstring for the new failure contract.

The docstring still says unsupported providers return None, but this path now raises PermanentUploadError. Document the exception instead, along with the optional dependency ImportError paths.

As per coding guidelines, public APIs should be documented accurately.

Suggested documentation update
-    Returns:
-        FileUploader instance for the provider, or None if not supported.
+    Returns:
+        FileUploader instance for the provider.
+    Raises:
+        PermanentUploadError: If the provider is unsupported or required
+            configuration is missing.
+        ImportError: If the provider SDK is unavailable.
🤖 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 220 -
222, Update the get_uploader() docstring to state that unsupported providers
raise PermanentUploadError instead of returning None, and document the
ImportError cases caused by unavailable optional dependencies. Keep the
documentation aligned with the method’s current failure behavior.

Source: Coding guidelines

🤖 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 200-203: Update the Bedrock S3 configuration error in the uploader
factory to mention both supported remediation paths: set
CREWAI_BEDROCK_S3_BUCKET or provide the bucket_name override. Keep the
corresponding debug log message consistent with this expanded guidance.

In `@lib/crewai-files/tests/test_uploader_factory.py`:
- Around line 10-18: Update both Bedrock tests, including
test_bare_raise_bedrock_no_config and the test at the referenced second
location, to accept pytest’s monkeypatch fixture and remove
CREWAI_BEDROCK_S3_BUCKET before calling get_uploader("bedrock"). Keep the
existing assertions and test behavior unchanged.

---

Nitpick comments:
In `@lib/crewai-files/src/crewai_files/uploaders/factory.py`:
- Around line 220-222: Update the get_uploader() docstring to state that
unsupported providers raise PermanentUploadError instead of returning None, and
document the ImportError cases caused by unavailable optional dependencies. Keep
the documentation aligned with the method’s current failure behavior.
🪄 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: a5b5105d-d59a-48e7-b276-6fbd2a3fb0e1

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb8753 and 1e47640.

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

Comment on lines +200 to +203
raise PermanentUploadError(
"Bedrock S3 uploader not configured. "
"Set CREWAI_BEDROCK_S3_BUCKET environment variable to enable."
)

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

Mention the supported bucket_name override in the error message.

This branch is also avoided when callers provide bucket_name, but the exception only instructs users to set the environment variable. Include both remediation paths, and keep the debug log message consistent.

Suggested wording
-                "Set CREWAI_BEDROCK_S3_BUCKET environment variable to enable."
+                "Set CREWAI_BEDROCK_S3_BUCKET or provide bucket_name via kwargs "
+                "to enable."
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
raise PermanentUploadError(
"Bedrock S3 uploader not configured. "
"Set CREWAI_BEDROCK_S3_BUCKET environment variable to enable."
)
raise PermanentUploadError(
"Bedrock S3 uploader not configured. "
"Set CREWAI_BEDROCK_S3_BUCKET or provide bucket_name via kwargs "
"to enable."
)
🤖 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 200 -
203, Update the Bedrock S3 configuration error in the uploader factory to
mention both supported remediation paths: set CREWAI_BEDROCK_S3_BUCKET or
provide the bucket_name override. Keep the corresponding debug log message
consistent with this expanded guidance.

Comment on lines +10 to +18
def test_bare_raise_bedrock_no_config(self):
"""get_uploader('bedrock') without bucket config raises PermanentUploadError,
not RuntimeError."""
raised = False
try:
get_uploader("bedrock")
except PermanentUploadError:
raised = True
assert raised, "expected PermanentUploadError for unconfigured bedrock"

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

Isolate the Bedrock tests from ambient environment state.

If CREWAI_BEDROCK_S3_BUCKET is set in CI or a developer environment, these tests will not exercise the missing-configuration branch. Remove the variable with the pytest monkeypatch fixture in both tests.

Suggested fix
-    def test_bare_raise_bedrock_no_config(self):
+    def test_bare_raise_bedrock_no_config(self, monkeypatch):
+        monkeypatch.delenv("CREWAI_BEDROCK_S3_BUCKET", raising=False)
         ...

-    def test_bedrock_message(self):
+    def test_bedrock_message(self, monkeypatch):
+        monkeypatch.delenv("CREWAI_BEDROCK_S3_BUCKET", raising=False)
         ...

Also applies to: 51-58

🤖 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/tests/test_uploader_factory.py` around lines 10 - 18, Update
both Bedrock tests, including test_bare_raise_bedrock_no_config and the test at
the referenced second location, to accept pytest’s monkeypatch fixture and
remove CREWAI_BEDROCK_S3_BUCKET before calling get_uploader("bedrock"). Keep the
existing assertions and test behavior unchanged.

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

2 participants