Conversation
Signed-off-by: w01fgang <sumin@unix-center.ru>
WalkthroughThe changes introduce a static error type ignore list to the Changes
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
Poem
✨ Finishing Touches
🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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:
- The test description is identical to the previous test ("should return the actual error")
- 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
📒 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.namemight 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 { $$$ }'
This PR introduces the ability to throw original errors instead of wrapped errors.
Summary by CodeRabbit