Skip to content

fix: exit non-zero when a file cannot be processed - #55

Merged
MPV merged 3 commits into
masterfrom
claude/nonzero-exit
Aug 9, 2026
Merged

fix: exit non-zero when a file cannot be processed#55
MPV merged 3 commits into
masterfrom
claude/nonzero-exit

Conversation

@MPV

@MPV MPV commented Jul 23, 2026

Copy link
Copy Markdown
Owner

What

Make kir fail loud via the exit code instead of silently reporting success. Two related fixes (the second folded in from #57):

  1. A file that can't be processed → non-zero exit. Per-file errors were logged but Run still returned 0.
  2. An argument that matches nothing → error + non-zero exit. filepath.Glob returns no matches and no error for both an empty glob and a missing literal path, so a typo was silently skipped.

Before → After

$ kir good.yaml broken.yaml; echo "exit=$?"
# before: prints good image, logs error, exit=0   ← success despite the error
# after:  prints good image, logs error, exit=1

$ kir typo.yaml; echo "exit=$?"
# before: (no output) exit=0                        ← typo silently ignored
# after:  error: no such file or match for "typo.yaml"  exit=1

Successes are still printed either way — kir is best-effort and never aborts the batch on one bad input; only the exit status changes.

Why

For a tool feeding a scanner (kir manifests/* | xargs grype), a zero exit must mean every input was understood. A parse failure or a mistyped path silently exiting 0 is the dangerous gap.

Tests

  • TestFailure/BadYAML (approval): malformed manifest through cmd.Run → error on stderr + exit 1 (exits 0 without this change).
  • TestCLI.MissingFile (approval): no-match argument → error + exit 1.
  • cmd_test.go TestRunFileFailure and fileutil unit tests cover the same at their layers.

Docs

Records the contract as docs/adr/0008-best-effort-processing-and-exit-codes.md (best-effort; failures surface via the exit code) and points ADR 0007's exit-column reference at it.

Release

Based on master. fix: → patch. (Combines the former #55 + #57, which is merged into this branch.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pc6NAURAqjU4LYJx93tgSC

@MPV
MPV force-pushed the claude/execute-returns-error branch from dea6982 to c060823 Compare July 23, 2026 07:14
@MPV
MPV force-pushed the claude/nonzero-exit branch from 54ee2ad to 10cad80 Compare July 23, 2026 07:19
@MPV
MPV force-pushed the claude/execute-returns-error branch from c060823 to b3973cd Compare July 23, 2026 08:17
@MPV
MPV force-pushed the claude/nonzero-exit branch from 10cad80 to 2163e29 Compare July 23, 2026 08:18
@MPV
MPV force-pushed the claude/execute-returns-error branch from b3973cd to d81dee0 Compare July 23, 2026 08:46
@MPV
MPV force-pushed the claude/nonzero-exit branch from 2163e29 to 33e1541 Compare July 23, 2026 08:49
@MPV
MPV force-pushed the claude/execute-returns-error branch from d81dee0 to 52bfab2 Compare July 24, 2026 06:45
@MPV
MPV force-pushed the claude/nonzero-exit branch from 33e1541 to 713ab54 Compare July 24, 2026 06:45
@MPV
MPV force-pushed the claude/nonzero-exit branch from 713ab54 to 2e16578 Compare August 2, 2026 07:57
@MPV
MPV changed the base branch from claude/execute-returns-error to master August 2, 2026 07:57
@MPV
MPV force-pushed the claude/nonzero-exit branch 2 times, most recently from d0e1a34 to 2d3647e Compare August 6, 2026 20:57
@MPV MPV changed the title Exit non-zero when a file cannot be processed fix: exit non-zero when a file cannot be processed Aug 6, 2026
@MPV
MPV force-pushed the claude/nonzero-exit branch 2 times, most recently from 53fe0b3 to ca552c8 Compare August 8, 2026 21:47
@MPV
MPV force-pushed the claude/nonzero-exit branch 3 times, most recently from ee7024e to 6d71fe7 Compare August 9, 2026 13:05
MPV pushed a commit that referenced this pull request Aug 9, 2026
#55 (exit non-zero on a processing failure) and #57 (error on a no-match
argument), now combined here, share one contract: kir processes the whole
batch, prints what it can, and exits non-zero if any input failed. Record
it as docs/adr/0008-best-effort-processing-and-exit-codes.md and point
ADR 0007's exit-column reference at it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pc6NAURAqjU4LYJx93tgSC
claude added 3 commits August 9, 2026 20:08
Per-file processing errors were logged but Run still returned 0, so a
pipeline like `kir manifests/* | xargs grype` could not tell that some
manifests failed to parse — the kind of silent gap that matters for a
tool feeding a vulnerability scanner.

Count per-file failures and, after processing every file, return a
non-zero exit code. Files that succeed are still printed; only the exit
status changes.

The behavioral golden suite pins this: TestFailure/BadYAML feeds a
malformed manifest through cmd.Run and asserts the error on stderr plus
exit 1 (without this change it exits 0). TestRunFileFailure covers the
same contract at the cmd unit level.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pc6NAURAqjU4LYJx93tgSC
filepath.Glob returns no matches and no error both for a glob that
matches nothing and for a literal path that does not exist, so a typo'd
filename was silently skipped: `kir typo.yaml` produced no output and
exited 0.

Treat an argument that resolves to zero files as an error naming that
argument; Run then reports it and exits non-zero.

The behavioral golden suite reflects this: TestCLI.MissingFile now exits
1 with the error on stderr.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pc6NAURAqjU4LYJx93tgSC
#55 (exit non-zero on a processing failure) and #57 (error on a no-match
argument), now combined here, share one contract: kir processes the whole
batch, prints what it can, and exits non-zero if any input failed. Record
it as docs/adr/0008-best-effort-processing-and-exit-codes.md and point
ADR 0007's exit-column reference at it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pc6NAURAqjU4LYJx93tgSC
@MPV
MPV force-pushed the claude/nonzero-exit branch from 887effa to 4b2374b Compare August 9, 2026 20:08
@MPV
MPV merged commit 655b764 into master Aug 9, 2026
1 check passed
@MPV
MPV deleted the claude/nonzero-exit branch August 9, 2026 20:12
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.

2 participants