resource-fmt: track failures and exit non-zero#630
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MustCheckTypelogged each failure viaklog.ErrorSand returned, somain()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.handlePanicrecovered without setting the named return values, so the post-recovery return was("", nil)— a panic insidecheck()reported "clean" to the caller.os.Exit(1)when non-zero. Convert recovered panics into a real error via a named return.fix=trueis preserved becausemake fmtinvokes the tool with no flags and depends on the fixing behaviour;make verify-genis what fails CI when the resulting tree is dirty.Test plan
go run ./cmd/resource-fmtexits 0 on a clean tree.hub/resourcedescriptors/…and confirm the tool exits 1 with a clear log line.check()(e.g. by corrupting a known-good RD) and confirmRECOVERis printed AND the process exits 1.🤖 Generated with Claude Code