fix(browser): catch malformed URL TypeError and map to exit 5 VALIDATION_ERROR#274
Open
sandman-sh wants to merge 1 commit into
Open
fix(browser): catch malformed URL TypeError and map to exit 5 VALIDATION_ERROR#274sandman-sh wants to merge 1 commit into
sandman-sh wants to merge 1 commit into
Conversation
|
✅ This PR is linked to an issue assigned to @sandman-sh — thanks! The |
Walkthrough
ChangesBrowser URL validation
Estimated code review effort: 2 (Simple) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Closes #276
Summary
Fixes un-guarded
new URL(url)call inopenInBrowser(src/lib/browser.ts) so malformed URLs return a clean CLIVALIDATION_ERROR(exit code 5) instead of crashing with an unhandled Node.jsTypeError.Problem
When
openInBrowser(url)receives a malformed or unparseable URL string (e.g."not a url"),new URL(url)throws a raw Node.jsTypeError: Invalid URL.Because this call was not wrapped in a
try/catchblock:file://already threwVALIDATION_ERROR(exit 5), creating an inconsistent error contract for bad inputs.Solution
Wrap
new URL(url)in atry/catchblock inopenInBrowser:Test Coverage
Updated src/lib/browser.test.ts to assert that malformed URL inputs throw
ApiErrorwithexitCode = 5. All unit tests pass.