Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve error handling in utapi #1125

Merged
merged 3 commits into from
Jan 10, 2025
Merged

fix: improve error handling in utapi #1125

merged 3 commits into from
Jan 10, 2025

Conversation

juliusmarminge
Copy link
Collaborator

@juliusmarminge juliusmarminge commented Jan 9, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling in the uploadthing component.
    • Improved logging and error reporting for file upload processes.
  • Tests

    • Added new test case to verify handling of failed file upload requests.
  • Chores

    • Updated test helper function visibility to support more comprehensive testing.

Copy link

changeset-bot bot commented Jan 9, 2025

🦋 Changeset detected

Latest commit: 3fe8445

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
uploadthing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2025 10:38pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Visit Preview Jan 10, 2025 10:38pm

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

The pull request focuses on enhancing error handling within the uploadthing component, specifically in the utapi module. The changes introduce improved error logging and management across multiple files, including the upload server, SDK utilities, and test helpers. The modifications ensure that errors are properly captured, logged, and reported during file upload processes, providing better visibility into error occurrences.

Changes

File Change Summary
packages/uploadthing/src/_internal/upload-server.ts Added logHttpClientError import and implemented error logging using Effect.tapError in uploadWithoutProgress function.
packages/uploadthing/src/sdk/utils.ts Enhanced error handling in uploadFile function with additional Effect.catchTag blocks for UploadThingError and ConfigError.
packages/uploadthing/test/__test-helpers.ts Changed callRequestSpy from a local constant to an exported function.
packages/uploadthing/test/sdk.test.ts Added a new test case for handling failed upload requests.

Sequence Diagram

sequenceDiagram
    participant Client
    participant UploadServer
    participant ErrorLogger
    participant HTTPClient

    Client->>UploadServer: Initiate File Upload
    UploadServer->>HTTPClient: Send Upload Request
    alt Upload Successful
        HTTPClient-->>UploadServer: Upload Complete
        UploadServer-->>Client: Success Response
    else Upload Fails
        HTTPClient-->>ErrorLogger: Log HTTP Client Error
        ErrorLogger->>UploadServer: Error Details
        UploadServer-->>Client: Structured Error Response
    end
Loading

Possibly related PRs

  • feat: return file hash from uploaded object #978: Enhances the onUploadComplete callback in the "uploadthing" functionality, which may relate to error handling improvements in the main PR by providing better tracking of uploaded objects.
  • fix: gracefully handle download errors #1058: Focuses on improving error handling in the utapi.uploadFilesFromUrl function, aligning with the main PR's goal of enhancing error management within the upload process.
  • feat: support more input parsers #1061: Addition of support for more input parsers, including error handling improvements, which could relate to the main PR's focus on enhancing error visibility and management in the upload functionality.

Suggested labels

✅ infra changes implemented, examples

Suggested reviewers

  • markflorkowski

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18da860 and 3fe8445.

📒 Files selected for processing (2)
  • packages/uploadthing/test/__test-helpers.ts (1 hunks)
  • packages/uploadthing/test/sdk.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/uploadthing/test/__test-helpers.ts
  • packages/uploadthing/test/sdk.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: typecheck
  • GitHub Check: analyze-bundle (current-pr)
  • GitHub Check: lint
  • GitHub Check: e2e-node (backend-adapters)
  • GitHub Check: e2e-node (minimal-pagedir)
  • GitHub Check: build
  • GitHub Check: e2e-node (minimal-appdir)
  • GitHub Check: build
  • GitHub Check: build

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the sdk label Jan 9, 2025
Copy link

pkg-pr-new bot commented Jan 9, 2025

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/uploadthing/src/_internal/upload-server.ts (1)

9-9: LGTM! Consider enhancing the error message.

The addition of error logging before error transformation is a good practice. However, the error message could be more descriptive.

Consider including more context in the error message:

-      Effect.tapError(logHttpClientError("Failed to upload file")),
+      Effect.tapError(logHttpClientError(`Failed to upload file: ${file.name}`)),

Also applies to: 28-28

packages/uploadthing/test/sdk.test.ts (1)

102-140: LGTM! Consider adding more error scenarios.

The test case effectively verifies the error handling for failed uploads. The implementation is clean and thorough.

Consider adding test cases for:

  1. Network errors (timeout, connection refused)
  2. Different HTTP error codes (500, 503)
  3. Malformed server responses

Example test case:

it("handles network errors gracefully", async () => {
  const mockedIngestUrl = "https://mocked.ingest.uploadthing.com";
  msw.use(
    http.all<{ key: string }>(
      `${mockedIngestUrl}/:key`,
      async () => {
        return HttpResponse.error();
      },
    ),
  );

  const utapi = new UTApi({
    token: testToken.encoded,
    ingestUrl: mockedIngestUrl,
  });
  const result = await utapi.uploadFiles(fooFile);
  expect(result.error?.code).toBe("UPLOAD_FAILED");
  
  msw.use(...handlers);
});
.changeset/curvy-rings-own.md (1)

5-7: Enhance the changeset description with more details.

While the description captures the essence of the change, it would be more helpful for future reference if you could expand it to include:

  • Specific examples of errors that were being ignored
  • Description of the new error handling behavior
  • Impact on existing implementations

Here's a suggested enhancement:

-fix: improve error handling in utapi
-
-sometimes errors got silently ignored when they shouldn't have
+fix: improve error handling in utapi
+
+Previously, certain errors during file upload processes were being silently ignored,
+particularly during HTTP client errors and presigned URL generation. This patch:
+
+- Adds proper error logging for HTTP client errors
+- Improves handling of UploadThingError and ConfigError
+- Ensures errors are properly propagated instead of being silently ignored
+
+This change improves debugging capabilities but doesn't introduce breaking changes
+to existing implementations.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1a1cf4 and 18da860.

📒 Files selected for processing (5)
  • .changeset/curvy-rings-own.md (1 hunks)
  • packages/uploadthing/src/_internal/upload-server.ts (3 hunks)
  • packages/uploadthing/src/sdk/utils.ts (2 hunks)
  • packages/uploadthing/test/__test-helpers.ts (1 hunks)
  • packages/uploadthing/test/sdk.test.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: typecheck
  • GitHub Check: analyze-bundle (current-pr)
  • GitHub Check: e2e-node (backend-adapters)
  • GitHub Check: e2e-node (minimal-pagedir)
  • GitHub Check: lint
  • GitHub Check: e2e-node (minimal-appdir)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (2)
packages/uploadthing/src/sdk/utils.ts (1)

123-125: LGTM! Robust error handling implementation.

The implementation properly handles specific error types and converts them to a consistent format. The error messages are clear and the error handling is comprehensive.

Also applies to: 134-136

packages/uploadthing/test/__test-helpers.ts (1)

67-67: LGTM! Good test organization.

Exporting the callRequestSpy function improves code reusability across test files.

Copy link
Contributor

github-actions bot commented Jan 9, 2025

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 30.07KB See Treemap 📊
PR (1e4d597) 30.07KB See Treemap 📊
Diff No change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant