Conversation
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Trace
Other
Bug Fixes 🐛Api
Formatters
Setup
Upgrade
Other
Documentation 📚
Internal Changes 🔧Api
Other
🤖 This preview updates automatically when you update the PR. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
… patterns
Add withAuthGuard<T>(fn, fallback, onError?) to src/lib/errors.ts that
encapsulates the 'try op, rethrow AuthError, return fallback' pattern
used across 16 call sites.
Changes:
- Add withAuthGuard helper function to errors.ts with JSDoc
- Convert 14 clean catch blocks (rethrow auth, return fallback)
- Convert 2 catch blocks using onError callback (project/create.ts
stores listTeamsError, resolve-target.ts throws ResolutionError on 404)
- Add unit tests (9 cases) and property-based tests (3 properties)
- Expand executeWithAutoAuth in bin.ts to also handle AuthError('expired')
in addition to 'not_authenticated', triggering interactive login flow
- Update app.ts to re-throw 'expired' AuthErrors for the auto-login flow
Files converted:
- src/lib/api-client.ts (4 sites)
- src/lib/resolve-target.ts (4 sites including fetchProjectId with onError)
- src/lib/org-list.ts (2 sites)
- src/commands/project/list.ts (4 sites)
- src/commands/project/view.ts (1 site)
- src/commands/project/create.ts (1 site with onError)
…login to expired tokens
Replace withAuthGuard's fallback+onError API with a discriminated
Result type (AuthGuardResult<T>) that gives callers direct access to
caught errors. This eliminates mutable error variables and closure-based
error handlers while keeping the same auth-propagation semantics.
Changes:
- withAuthGuard now returns { ok, value } | { ok, error } instead of
accepting fallback and onError parameters
- Export AuthGuardSuccess<T>, AuthGuardFailure, AuthGuardResult<T> types
- Convert 4 remaining manual instanceof AuthError catch patterns
(region.ts, project/list.ts handleExplicit, issue/list.ts
fetchIssuesForTarget)
- Expand auto-login flow in bin.ts and app.ts to also trigger on
AuthError("expired"), with context-aware messaging
- Update telemetry.ts to suppress Sentry capture for expired tokens
12 files changed, net -45 lines.
7ae1838 to
3ecdd80
Compare
Contributor
Codecov Results 📊✅ 101 passed | Total: 101 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 83.72%. Project has 3526 uncovered lines. Files with missing lines (11)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 81.52% 81.61% +0.09%
==========================================
Files 127 127 —
Lines 19227 19177 -50
Branches 0 0 —
==========================================
+ Hits 15673 15651 -22
- Misses 3554 3526 -28
- Partials 0 0 —Generated by Codecov Action |
…ture of expected auth errors
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.
Replace
withAuthGuard'sfallback+onErrorAPI with a discriminated Result type (AuthGuardResult<T>) that gives callers direct access to caught errors. This eliminates mutable error variables and closure-based error handlers while keeping the same auth-propagation semantics.Changes
withAuthGuardAPI redesign — now returns{ ok: true, value: T } | { ok: false, error: unknown }instead of acceptingfallbackandonErrorparameters. Exported types:AuthGuardSuccess<T>,AuthGuardFailure,AuthGuardResult<T>.instanceof AuthErrorcatch patterns —region.ts(×2),project/list.tshandleExplicit,issue/list.tsfetchIssuesForTargetbin.tsandapp.tsnow also trigger interactive login onAuthError("expired"), with context-aware messagingwithAuthGuardunit and property-based tests for new Result type APIImpact
withAuthGuardcall sites migratedinstanceof AuthErrorpatterns remain (3 infrastructure, 5 intentionally kept for specialized semantics)onErrorcallback removed entirely (was used by only 2 of 15 call sites)