Skip to content

resource-fmt: track failures and exit non-zero#630

Merged
tamalsaha merged 1 commit into
masterfrom
fix/resource-fmt-exit-code
May 19, 2026
Merged

resource-fmt: track failures and exit non-zero#630
tamalsaha merged 1 commit into
masterfrom
fix/resource-fmt-exit-code

Conversation

@tamalsaha
Copy link
Copy Markdown
Contributor

Summary

  • MustCheckType logged each failure via klog.ErrorS and returned, so main() always exited 0 — CI claims the tool enforced an invariant but it never did. A malformed RD would merge silently with a loud-looking error line in the log.
  • handlePanic recovered without setting the named return values, so the post-recovery return was ("", nil) — a panic inside check() reported "clean" to the caller.
  • Track failures in a package-level counter, os.Exit(1) when non-zero. Convert recovered panics into a real error via a named return.
  • Default fix=true is preserved because make fmt invokes the tool with no flags and depends on the fixing behaviour; make verify-gen is what fails CI when the resulting tree is dirty.

Test plan

  • Normal run: go run ./cmd/resource-fmt exits 0 on a clean tree.
  • Introduce a YAML with a typed-field error in hub/resourcedescriptors/… and confirm the tool exits 1 with a clear log line.
  • Trigger a panic in check() (e.g. by corrupting a known-good RD) and confirm RECOVER is printed AND the process exits 1.

🤖 Generated with Claude Code

MustCheckType used to klog.ErrorS the failure and return, so main()
never saw an error and the process always exited 0. Combined with
handlePanic — which recovered silently and let the function return
("", nil) via its zero-value returns — bad YAML or parse panics in
hub/ produced loud-looking output but kept CI green.

Track failures in a counter, exit 1 if any occurred. Convert the
recovered panic into a proper error via a named return so the caller
no longer sees a clean nil.

The Makefile `fmt` target relies on `fix=true` as the default, so
that default is unchanged; `make verify-gen` already catches the
resulting diff in CI.

Signed-off-by: Tamal Saha <tamal@appscode.com>
@tamalsaha tamalsaha merged commit 94885eb into master May 19, 2026
6 checks passed
@tamalsaha tamalsaha deleted the fix/resource-fmt-exit-code branch May 19, 2026 15:19
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.

1 participant