fix: include stdout in commit() error when stderr is empty - #19
Merged
Conversation
When git commit fails with no stderr output, the error message was just 'git commit exited with code 1' with no useful detail. git sometimes writes failure output to stdout instead of stderr. Join both stderr and stdout (filtering empty strings) so the full git output is always surfaced in the thrown error. Closes 404-PF#17
404-Page-Found
approved these changes
May 27, 2026
404-Page-Found
left a comment
Contributor
There was a problem hiding this comment.
PR Review: fix: include stdout in commit() error when stderr is empty
Overview
Fixes a bug where failed git commit calls could produce unhelpful error messages when stderr is empty but stdout contains failure details (e.g., pre-commit hook output). Combines both streams before constructing the error, falling back to the generic message only if both are empty.
Code Quality
- Clean, idiomatic pattern (
filter(Boolean).join('\n').trim()) consistent with the existinggetCombinedDiff()function on line 44. - Minimal, well-scoped change — +2/−1 lines, no new dependencies.
- Readable and maintainable.
Potential Issues
- Whitespace-only streams: Handled correctly —
.trim()on the joined result means thedetail || ...fallback catches effectively empty strings. - No tests: Acknowledged by the author. Acceptable for this scope.
Suggestions
- No blocking suggestions. The code is fine as-is.
Verdict
✅ Approve — Correct, well-documented, follows project conventions.
MohammadYusif
added a commit
to MohammadYusif/commit-echo
that referenced
this pull request
May 28, 2026
fix: include stdout in commit() error when stderr is empty
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
When
git commitfails with no stderr output, the thrown error message was just "git commit exited with code 1" with no useful detail. This fix captures both stderr and stdout so the full git output is always included in the error.Why this change
spawnSyncreturns bothresult.stderrandresult.stdout, but the original code only fell back toresult.stderr. Git sometimes writes failure output to stdout instead of stderr (e.g. pre-commit hook failures, nothing to commit messages), leaving the error completely blank for the user.What changed
src/git/diff.ts: joinresult.stderrandresult.stdout, filter empty strings, trim — use the combined output as the error detailgit commit exited with code Nmessage only if both streams are emptyValidation
npm run build— clean, no TypeScript errorsUser-facing impact
Error message shown to the user on a failed commit is now more informative. No behavior change on the happy path.
Notes
No tests exist in this repo yet. The fix is a one-line logic change in a small, focused function.