fix: degrade gracefully when git is unavailable or diff base ref is missing#930
Merged
Conversation
…issing Closes REACT-DOCTOR-F, REACT-DOCTOR-1K, REACT-DOCTOR-14, REACT-DOCTOR-22 When git binary is not installed or the diff base ref cannot be resolved, the scan now falls back to a full scan with a clear warning instead of crashing and reporting to Sentry. Changes: - Modified branchExists() to catch GitInvocationFailed and return false instead of propagating the error - Modified diffSelection() to return null when branchExists returns false for an explicit base, allowing graceful degradation - Updated warnDiffUnavailable() to mention git unavailability and missing refs as possible causes - Added comprehensive tests for both git-missing and ref-missing scenarios Co-authored-by: Skosh <skoshx@users.noreply.github.com>
Co-authored-by: Skosh <skoshx@users.noreply.github.com>
commit: |
The initial fix was too broad - it converted missing refs to null, but the existing behavior (throwing GitBaseBranchMissing) is correct for user errors. The key fix is that branchExists() now catches GitInvocationFailed (git binary missing) and converts it to false, which then becomes GitBaseBranchMissing - an expected user error that doesn't report to Sentry. - Git missing → branchExists returns false → GitBaseBranchMissing → user error - Ref doesn't exist → branchExists returns false → GitBaseBranchMissing → user error Both are now handled the same way without Sentry spam. Co-authored-by: Skosh <skoshx@users.noreply.github.com>
The graceful-degradation work dropped the comment explaining why `currentBranch` swallows a git-spawn failure to null (so auto-detect degrades instead of crashing). The behavior is unchanged and still load-bearing, so the rationale is worth keeping next to it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment on lines
+441
to
+445
| Effect.catch((error) => | ||
| error.reason._tag === "GitInvocationFailed" | ||
| ? Effect.succeed(false) | ||
| : Effect.fail(error), | ||
| ), |
Contributor
There was a problem hiding this comment.
🟡 AGENTS.md violation: Manual _tag dispatch inside Effect.catch instead of Effect.catchReasons
The AGENTS.md mandates: "Effect.catchReasons(errorTag, cases, orElse?) — the v4-canonical way to dispatch on a Schema.TaggedErrorClass reason union. … NEVER write manual if (cause.reason instanceof X) ladders inside a catch block." The new code manually checks error.reason._tag === "GitInvocationFailed" inside an Effect.catch block, which is the exact dispatch-on-reason-inside-catch pattern the rule prohibits. The codebase's canonical Effect.catchReasons usage is at packages/core/src/errors.ts:228-241 (restoreLegacyThrow).
Suggested change
| Effect.catch((error) => | |
| error.reason._tag === "GitInvocationFailed" | |
| ? Effect.succeed(false) | |
| : Effect.fail(error), | |
| ), | |
| Effect.catchReasons( | |
| "ReactDoctorError", | |
| { | |
| GitInvocationFailed: () => Effect.succeed(false), | |
| }, | |
| (_reason, error) => Effect.fail(error), | |
| ), |
Was this helpful? React with 👍 or 👎 to provide feedback.
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
Fixes a crash when git is not installed or the
--diffbase ref isn't present in the checkout (both common in CI containers and shallow clones). When git is unavailable, the scan now throwsGitBaseBranchMissing(an expected user error) instead ofGitInvocationFailed, preventing Sentry spam while still giving users a clear error message.Closes #923
Root Cause
Two separable conditions caused Sentry-reported crashes (REACT-DOCTOR-F (76 events), REACT-DOCTOR-1K, REACT-DOCTOR-14, REACT-DOCTOR-22):
ENOENT→PlatformError→ wrapped inGitInvocationFailed→ reported to Sentrygit rev-parse --verify <base>exits non-zero, but the error was wrapped inGitInvocationFailedinstead ofGitBaseBranchMissingBoth threw
ReactDoctorError({ reason: GitInvocationFailed })which was NOT inisExpectedUserError, so it was reported to Sentry as a crash.Fix Approach
The key insight: both "git missing" and "ref doesn't exist" should surface as
GitBaseBranchMissing(an expected user error that triggers the existing fallback-to-full-scan logic and is NOT reported to Sentry).Before:
GitInvocationFailed→ reported to Sentry ❌GitInvocationFailed→ reported to Sentry ❌After:
branchExistscatchesGitInvocationFailed, returnsfalse→GitBaseBranchMissing→ clean user error, NOT reported to Sentry ✅branchExistsreturnsfalse→GitBaseBranchMissing→ clean user error, NOT reported to Sentry ✅Changes
Core (
@react-doctor/core)branchExists(): Now catchesGitInvocationFailed(git binary missing) and returnsfalseinstead of propagating the errordiffSelection()andresolveDiffRange(): Unchanged - still throwGitBaseBranchMissingwhenbranchExistsreturnsfalse, maintaining existing behaviorCLI (
react-doctor)warnDiffUnavailable(): Updated message to mention "git unavailable, ref not found, or merge-base failed"isExpectedUserError(): Already handlesGitBaseBranchMissing(no changes needed)Tests
git-missing-binary.test.ts: Verifies that git unavailability converts toGitBaseBranchMissinggit-missing-ref.test.ts(covered by existingdiff-commit-range.test.ts)Behavior
Users see the SAME error message in both cases:
The difference is internal: previously
GitInvocationFailedwas reported to Sentry; nowGitBaseBranchMissingtriggers the existing clean-error path.Testing
diff-commit-range.test.tswhich expects the throw)GitBaseBranchMissingconversionpnpm test,pnpm lint,pnpm typecheckall pass