Skip to content

[Reliability] process.exit(1) after outro()/console.log can truncate CLI output #270

Description

@404-Page-Found

Summary

Several commands call process.exit(1) immediately after outro() / console.log. Node's process.exit() does not flush pending stdout writes, so when output is piped (e.g. commit-echo config --json | jq), the final lines can be truncated or lost entirely. These calls also skip cleanup. Note src/commands/suggest.ts:147 already uses the correct pattern (process.exitCode = 1; return;).

Location

  • src/commands/suggest.ts:339 (auto-commit without staged changes), :421 (commit failure)
  • src/commands/config.ts:185 (config --json with no config), :221, :227, :248 (config set error paths)
  • src/commands/completion.ts:701 (unsupported shell)

Code snippet

// src/commands/config.ts
console.log(JSON.stringify({ error: 'No configuration found...' }, null, 2));
process.exit(1); // ← can truncate the JSON above when stdout is a pipe

Suggested fix

Replace process.exit(1) with process.exitCode = 1; return; in these error paths (matching suggest.ts:147), so stdout flushes before the process exits.

Impact

  • Scripted usage (config --json, completion, suggest --commit) can receive truncated output with an error exit code, corrupting pipelines.
  • Inconsistent with the established in-repo pattern for setting a failing exit code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions