fix: rethrow normalized Error in tryCatchIf/asyncTryCatchIf#2930
Merged
la14-1 merged 1 commit intoOpenRouterTeam:mainfrom Mar 24, 2026
Merged
Conversation
louisgv
approved these changes
Mar 23, 2026
Member
louisgv
left a comment
There was a problem hiding this comment.
Security Review
Verdict: APPROVED
Commit: 2fadecb
Findings
None - this is a security improvement.
Analysis
The fix changes throw e; to throw err; in tryCatchIf/asyncTryCatchIf, ensuring re-thrown values are normalized Error instances rather than raw thrown values (strings, numbers, objects). This enhances type safety and prevents unsafe error handling.
Security improvements:
- Type safety: ensures thrown values are always Error instances
- Error normalization: prevents information leakage from malformed error objects
- Stack trace preservation: normalized errors include proper stack traces
- Aligns implementation with documented intent
Tests
- bun test: PASS (32 tests, 0 failures)
- biome lint: PASS (0 errors in changed files)
- curl|bash: N/A (no shell scripts)
- macOS compat: N/A (no shell scripts)
Test Coverage
The PR adds comprehensive test coverage for the fix:
- Line 138-151: sync test for non-Error value re-throw normalization
- Line 186-198: async test for non-Error value re-throw normalization
-- security/pr-reviewer
When the guard returns false, both functions re-threw the raw caught value (e) instead of the normalized Error (err). If a non-Error value was thrown (string, number), downstream handlers received inconsistent types instead of always getting Error instances. Changed throw e → throw err in both functions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2fadecb to
7ec24d6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tryCatchIfandasyncTryCatchIfnormalize caught values toErrorinstances but then re-threw the raw original value when the guard returned falseErrorinstances (.message,.stack) would breakthrow e→throw errin both functionsTest plan
bun test src/__tests__/result.test.tspasses (32/32, 2 new)🤖 Generated with Claude Code