Skip to content

✨ allow throwing original errors#11

Merged
w01fgang merged 1 commit intomainfrom
feature/allow-throwing-original-errors
Jun 25, 2025
Merged

✨ allow throwing original errors#11
w01fgang merged 1 commit intomainfrom
feature/allow-throwing-original-errors

Conversation

@w01fgang
Copy link
Copy Markdown
Contributor

@w01fgang w01fgang commented Jun 25, 2025

This PR introduces the ability to throw original errors instead of wrapped errors.

Summary by CodeRabbit

  • New Features
    • Added the ability to configure specific error types to bypass error wrapping and be rethrown directly.
  • Documentation
    • Enhanced and expanded usage documentation for all public methods, including detailed examples and behavior explanations.
  • Tests
    • Added and updated tests to verify new error handling behavior and ensure correct functionality.
  • Chores
    • Updated the package version.

Signed-off-by: w01fgang <sumin@unix-center.ru>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 25, 2025

Walkthrough

The changes introduce a static error type ignore list to the Try class, allowing specified error types to bypass error wrapping and be rethrown directly. Comprehensive JSDoc documentation was added throughout the Try class. Tests were updated to cover the new error bypass logic, and the package version was incremented.

Changes

File(s) Change Summary
package.json Updated the package version from "0.0.4" to "0.0.5".
src/nextjs/index.ts Added static error type ignore list and method to configure it in Try class; enhanced JSDoc documentation; adjusted error wrapping logic in unwrap().
src/tests/Try.test.ts Added tests for custom error bypass logic, including a new error class and afterEach reset; improved formatting.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Try
  participant Error

  Caller->>Try: new Try(fn)
  Caller->>Try: Try.throwThroughErrorTypes(['GraphQLError'])
  Caller->>Try: await Try.unwrap()
  Try->>Error: Execute fn()
  alt Error thrown and name in ignoreErrorTypes
    Try-->>Caller: Rethrow original Error
  else Error thrown and name not in ignoreErrorTypes
    Try-->>Caller: Throw wrapped Error
  else No Error
    Try-->>Caller: Return result
  end
Loading

Poem

In the garden of code where errors might grow,
A rabbit now hops where exceptions may flow.
With a flick of its paw, some errors pass through—
"Ignore these!" it says, letting custom ones chew.
Version hops up, docs bloom anew,
Testing the trails where the wild bugs flew!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch feature/allow-throwing-original-errors

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests 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 or @coderabbitai title 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.

Copy link
Copy Markdown

@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 (1)
src/__tests__/Try.test.ts (1)

209-218: Test case has duplicate description and could be more descriptive.

The test correctly validates the error throwing behavior, but there are two issues:

  1. The test description is identical to the previous test ("should return the actual error")
  2. The test name doesn't clearly describe what it's testing

Apply this diff to fix the test description:

-  it('should return the actual error', async () => {
+  it('should throw original error when error type is configured to throw through', async () => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 966d376 and 7d30d2d.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/__tests__/Try.test.ts (4 hunks)
  • src/nextjs/index.ts (7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/__tests__/Try.test.ts (1)
src/nextjs/index.ts (1)
  • Try (33-440)
🔇 Additional comments (8)
package.json (1)

3-3: Version bump looks good.

The version increment from 0.0.4 to 0.0.5 appropriately reflects the new error handling functionality being added.

src/__tests__/Try.test.ts (2)

24-31: Good test setup for custom error types.

The GraphQLError class and helper function are properly structured to test the new error throwing functionality.


52-52: Essential cleanup to prevent test contamination.

Resetting the throwThroughErrorTypes configuration after each test ensures test isolation and prevents side effects between tests.

src/nextjs/index.ts (5)

39-39: Static property implementation looks correct.

The static ignoreErrorTypes array properly stores the configured error types that should bypass wrapping.


91-93: Static method correctly updates the ignore list.

The throwThroughErrorTypes method properly assigns the provided array to the static property, enabling the configuration of error types to throw through.


41-93: Comprehensive JSDoc documentation enhances usability.

The detailed JSDoc comments with examples greatly improve the developer experience and make the API more discoverable and understandable.


210-254: unwrap method documentation is thorough and helpful.

The expanded JSDoc documentation clearly explains the method's behavior, including the interaction with the new error type configuration and various usage scenarios.


247-247: Error checking logic is correct but consider edge cases.

The logic correctly checks if the error name is in the ignore list before deciding whether to wrap the error. However, consider potential edge cases where result.error.name might be undefined or empty.

Let me verify how JavaScript handles error names and potential edge cases:

#!/bin/bash
# Check if there are any custom error classes in the codebase that might not have proper names
ast-grep --pattern 'class $_ extends Error {
  $$$
}'

@w01fgang w01fgang merged commit 11c544d into main Jun 25, 2025
3 checks passed
@w01fgang w01fgang deleted the feature/allow-throwing-original-errors branch June 25, 2025 09:03
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.

1 participant