Skip to content

fix(commit): --print-message failures are no longer silent (CMD-15) - #2117

Merged
gfargo merged 1 commit into
mainfrom
fix/cmd15-print-message-silent-failures
Aug 14, 2026
Merged

fix(commit): --print-message failures are no longer silent (CMD-15)#2117
gfargo merged 1 commit into
mainfrom
fix/cmd15-print-message-silent-failures

Conversation

@gfargo

@gfargo gfargo commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • coco commit --print-message — the exact non-interactive command the installed prepare-commit-msg hook runs on every plain git commit — logged draft-generation warnings/validation errors through logger.verbose, which no-ops unless --verbose is set. A failure (e.g. missing API key) exited 1 with zero output anywhere: no stdout, no stderr, nothing. git commit would just open an empty editor with no explanation.
  • This path also bypassed handleMissingApiKey (only called later, well after this early-return branch), so the curated "set OPENAI_API_KEY / run coco init" recovery copy every other command gets was replaced by a generic (and, per the bug above, invisible) validationErrors string.
  • Fix:
    • logger.verboselogger.error for warnings/validation errors on this path, so they survive without --verbose.
    • Plain --print-message (not --json) now calls handleMissingApiKey up front when the configured provider has no key, before attempting generateCommitDraft at all.
    • --json is left alone: it already has its own { error } stdout contract from the existing emitJson call on this path, which needs to stay machine-readable rather than switching to the human-formatted hint.

Closes #1888

Test plan

  • New tests in commit.test.ts: failures on this path now surface via logger.error (not logger.verbose); a missing API key shows the curated hint and skips generateCommitDraft entirely; --json still emits a parseable { error } payload for the same missing-key case rather than the human-formatted hint
  • npx jest src/commands/commit — 252/252 passed
  • npx tsc --noEmit -p . — clean
  • npx jest (full suite) — pre-existing, unrelated tree-sitter WASM failures only (same 4 failures present on a clean origin/main checkout in this worktree)

--print-message and --json share a draft-only path that logged
warnings/validationErrors through logger.verbose, which no-ops unless
--verbose is set. The exact non-interactive command the installed
prepare-commit-msg hook runs (coco commit --print-message) could exit
1 with zero output anywhere.

Routes those through logger.error instead. Plain --print-message also
gets the curated "set OPENAI_API_KEY / run coco init" missing-key hint
up front, matching every other command, instead of a bare
validationError further down. --json keeps its existing contract
(a parseable { error } payload on stdout) rather than the human-
formatted hint, since it needs stdout to stay machine-readable.
@gfargo
gfargo merged commit 184d4f5 into main Aug 14, 2026
12 checks passed
@gfargo
gfargo deleted the fix/cmd15-print-message-silent-failures branch August 14, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CMD-15: fix(commit): --print-message failures are completely silent and skip the missing-API-key hint

1 participant