From 1d06fb5f8a17ad88347b01b0bfc38e66f90b0224 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Tue, 19 May 2026 21:16:43 +0600 Subject: [PATCH] resource-fmt: track failures and exit non-zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cmd/resource-fmt/main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/resource-fmt/main.go b/cmd/resource-fmt/main.go index 14cac69be1..31205b6bfb 100644 --- a/cmd/resource-fmt/main.go +++ b/cmd/resource-fmt/main.go @@ -35,15 +35,16 @@ import ( "sigs.k8s.io/yaml" ) -func handlePanic(filename string) { +func handlePanic(filename string, retErr *error) { a := recover() if a != nil { fmt.Println("RECOVER", filename, a) + *retErr = fmt.Errorf("panic while processing %s: %v", filename, a) } } -func check(typ reflect.Type, filename string, fix bool) (string, error) { - defer handlePanic(filename) +func check(typ reflect.Type, filename string, fix bool) (out string, err error) { + defer handlePanic(filename, &err) data, err := os.ReadFile(filename) if err != nil { @@ -135,9 +136,12 @@ func checkType(t any, plural string, fix bool) error { }) } +var failures int + func MustCheckType(t any, plural string, fix bool) { if err := checkType(t, plural, fix); err != nil { klog.ErrorS(err, "failed to check "+plural) + failures++ } } @@ -153,4 +157,8 @@ func main() { MustCheckType(metaapi.ResourceOutline{}, "resourceoutlines", *fix) MustCheckType(metaapi.ResourceTableDefinition{}, "resourcetabledefinitions", *fix) MustCheckType(uiapi.ResourceDashboard{}, "resourcedashboards", *fix) + + if failures > 0 { + os.Exit(1) + } }