Catch per-command failures in gatherGitSnapshot#243
Merged
Conversation
Phase 1 of the fix for issue #242. gatherGitSnapshot now accepts an optional runner parameter (default: runGit) so tests can inject a function that throws without spawning real git processes. Adds a test that reproduces the crash: injects a runner that rejects for [rev-parse, HEAD] (all other commands return empty string) and asserts the snapshot resolves with head empty string. The test is deliberately failing at this stage because no .catch() guards have been added yet.
The four git commands in gatherGitSnapshot ran in parallel via Promise.all with no error handling. If any command failed (e.g. git rev-parse HEAD in a repo with no commits, exit code 128), the rejection propagated out of Promise.all and crashed the process. Fix: add .catch(() => '') to each runner call. Failed commands default to an empty string. The existing parsers already handle empty strings correctly: parseHead returns '', parseBranch returns '', parseStatus returns empty arrays, parseStash returns 0. The snapshot degrades gracefully instead of killing the process. Fixes #242
bananabot9000
approved these changes
Apr 10, 2026
Collaborator
bananabot9000
left a comment
There was a problem hiding this comment.
Clean fix for the empty-repo crash. .catch(() => '') on each Promise.all member is the right approach — graceful degradation per command, not a blanket catch on the whole Promise.all.
The injectable runner parameter for testability is a nice touch — no mocking execFile, no filesystem setup, just inject a function. Test is focused: rejects for rev-parse HEAD, empty string for everything else, asserts head: ''.
Session log is a good example of the new delivery notes pattern in action.
Approve.
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
gatherGitSnapshotran viaPromise.allwith no error handlinggit rev-parse HEADin a repo with no commits, exit code 128), the rejection crashed the process.catch(() => '')to each runner call so failures degrade gracefully to empty stringparseHeadreturns'',parseBranchreturns'',parseStatusreturns empty arrays,parseStashreturns0Related Issues
Fixes #242
Co-Authored-By: Claude noreply@anthropic.com