Bug Description
suggestCommand does not wrap getStagedDiff() / getUnstagedDiff() in try/catch, causing unhandled crashes with raw stack traces on any git failure.
Steps to Reproduce
- Be inside a git repository
- Simulate a git error condition (e.g., run in a bare repository, or after the
git binary is moved/removed from PATH after checkGitRepo() passes)
- Run
commit-echo suggest
Expected Behavior
A user-friendly error message is displayed and the command exits gracefully.
Actual Behavior
The raw execSync error propagates up with an ugly stack trace.
Root Cause
src/commands/suggest.ts:108 — the diff retrieval is unprotected. This is inconsistent with other code paths:
checkGitRepo() at line 90 IS properly wrapped in try/catch (lines 89-94)
src/commands/batch.ts wraps its equivalent getGitDiff() in try/catch (lines 235-241)
Suggested Fix
Wrap the diff retrieval in try/catch:
let diffResult: DiffResult;
try {
diffResult = getStagedDiff();
} catch (err) {
outro(pc.red(`Failed to read staged diff: ${err instanceof Error ? err.message : String(err)}`));
return;
}
Environment
- commit-echo latest
- Node.js (any version)
Bug Description
suggestCommanddoes not wrapgetStagedDiff()/getUnstagedDiff()in try/catch, causing unhandled crashes with raw stack traces on any git failure.Steps to Reproduce
gitbinary is moved/removed from PATH aftercheckGitRepo()passes)commit-echo suggestExpected Behavior
A user-friendly error message is displayed and the command exits gracefully.
Actual Behavior
The raw
execSyncerror propagates up with an ugly stack trace.Root Cause
src/commands/suggest.ts:108— the diff retrieval is unprotected. This is inconsistent with other code paths:checkGitRepo()at line 90 IS properly wrapped in try/catch (lines 89-94)src/commands/batch.tswraps its equivalentgetGitDiff()in try/catch (lines 235-241)Suggested Fix
Wrap the diff retrieval in try/catch:
Environment