Skip to content

fix: accept literals instead of labels#1164

Merged
juliusmarminge merged 3 commits intomainfrom
config-literal
Mar 7, 2025
Merged

fix: accept literals instead of labels#1164
juliusmarminge merged 3 commits intomainfrom
config-literal

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Mar 7, 2025

Closes #1163

Config.logLevel accepts a label and not a literal, but have gotten a hint that this will change in Effect 4.0 so instead of changing our types to match the current behavior, I figured we'll just start accepting literals

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue with logging configuration validation to ensure only valid log levels are accepted.
  • New Features

    • Introduced enhanced error handling for logging settings, defaulting to a standard log level when provided values are invalid.
    • Added a new function for improved mapping of log levels to enhance clarity in configuration.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 7, 2025

🦋 Changeset detected

Latest commit: d12ede1

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

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 7, 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 Mar 7, 2025 3:45pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Visit Preview Mar 7, 2025 3:45pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 7, 2025

Walkthrough

This pull request introduces a new changeset file documenting a patch for the "uploadthing" component configuration validator. It updates internal logger functionality by adding a new function, ConfigLogLevel, which replaces the previous implementation of withMinimalLogLevel. The new function improves log level validation by mapping string inputs to defined log levels with explicit error handling using Config.mapOrFail, Either, and ConfigError.InvalidData.

Changes

File(s) Change Summary
.changeset/.../fair-pets-leave.md New file added to document a patch for the "uploadthing" component, specifically fixing the configuration validator to ensure proper log level type matching.
packages/uploadthing/src/_internal/logger.ts Introduces ConfigLogLevel to replace the old withMinimalLogLevel implementation. This new function uses Config.mapOrFail to convert a string to a log level, returns an error via Either.left with ConfigError.InvalidData for invalid entries, and sets a default of LogLevel.Info for valid cases. Added necessary imports.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant L as ConfigLogLevel
    participant M as Config.mapOrFail
    participant E as Error Handler

    C->>L: Request log level configuration
    L->>M: Validate input string for log level
    alt Valid log level found
        M-->>L: Return valid log level (Right)
        L-->>C: Respond with log level configuration
    else Invalid log level
        M-->>L: Return error indicator
        L->>E: Generate ConfigError.InvalidData
        L-->>C: Respond with error (Left)
    end
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

Scope: all 3 workspace projects
/tmp/eslint/packages/uploadthing:
 ERR_PNPM_WORKSPACE_PKG_NOT_FOUND  In packages/uploadthing: "@uploadthing/mime-types@workspace:*" is in the dependencies but no package named "@uploadthing/mime-types" is present in the workspace

This error happened while installing a direct dependency of /tmp/eslint/packages/uploadthing

Packages found in the workspace:


📜 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 9343935 and d12ede1.

📒 Files selected for processing (1)
  • packages/uploadthing/src/_internal/logger.ts (2 hunks)
⏰ 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: build
  • GitHub Check: e2e-node (minimal-pagedir)
  • GitHub Check: e2e-node (minimal-appdir)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (5)
packages/uploadthing/src/_internal/logger.ts (5)

7-7: Import added for error handling

Good addition of the ConfigError import to support the new error handling in the ConfigLogLevel function.


9-9: Import added for functional data type

Good addition of the Either import to support the new error handling pattern.


18-23: Well-documented implementation change

The comment clearly explains why this custom implementation is needed and when it can be removed in the future. This helps future maintainers understand the reasoning behind this code.


24-37: Good implementation of log level validation from literals

This implementation correctly maps string literals to LogLevel objects using the _tag property, with proper error handling for invalid values. The function signature is flexible with the optional name parameter.

This implementation follows the pattern from Effect but adapts it to work with literals directly, which aligns with your comment about Effect 4.0's direction.


39-39: Updated to use new ConfigLogLevel implementation

The implementation correctly uses the new ConfigLogLevel function while maintaining all the existing error handling and default behavior.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

* Config.logLevel counter-intuitively accepts LogLevel["label"]
* instead of a literal, ripping it and changing to accept literal
*/
export const ConfigLogLevel = (
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is taken from the official Config.logLevel and just change to accept literal instead.

see https://github.com/Effect-TS/effect/blob/a55835a5c564b19222c728c9ca8beb145066a2a5/packages/effect/src/internal/config.ts#L296-L305

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 7, 2025

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 7, 2025

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 30.66KB See Treemap 📊
PR (e789337) 30.66KB See Treemap 📊
Diff No change

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]: Expected a log level but received Warning

2 participants