From 8d5a343fbe74cbf5283c3f2a7b25a5671a6f2698 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 14 Aug 2025 02:38:22 +0000 Subject: [PATCH] Restore original panic logic in toCLIError function as requested Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> --- cmd/root.go | 4 +-- cmd/root_test.go | 66 ------------------------------------------------ 2 files changed, 2 insertions(+), 68 deletions(-) delete mode 100644 cmd/root_test.go diff --git a/cmd/root.go b/cmd/root.go index 8d185913..ed629d12 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,6 +1,7 @@ package cmd import ( + "fmt" "os" "github.com/spf13/cobra" @@ -34,8 +35,7 @@ func toCLIError(g *config.GlobalImpl, err error) error { case *app.Error: return errors.NewExitError(e.Error(), e.Code()) default: - // Handle any other error type gracefully with exit code 1 - return errors.NewExitError(e.Error(), 1) + panic(fmt.Errorf("BUG: please file an github issue for this unhandled error: %T: %v", e, e)) } } return err diff --git a/cmd/root_test.go b/cmd/root_test.go deleted file mode 100644 index 4964522a..00000000 --- a/cmd/root_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package cmd - -import ( - "fmt" - "testing" - - "github.com/helmfile/helmfile/pkg/config" - "github.com/helmfile/helmfile/pkg/errors" -) - -func TestToCLIError(t *testing.T) { - globalCfg := &config.GlobalImpl{} - - tests := []struct { - name string - err error - wantCode int - wantErr bool - }{ - { - name: "nil error", - err: nil, - wantErr: false, - }, - { - name: "regular error (like from fmt.Errorf) - this was causing the panic", - err: fmt.Errorf("invalid semantic version"), - wantCode: 1, - wantErr: true, - }, - { - name: "another regular error type", - err: fmt.Errorf("some other error"), - wantCode: 1, - wantErr: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - // This should not panic for any error type - defer func() { - if r := recover(); r != nil { - t.Errorf("toCLIError() panicked: %v", r) - } - }() - - err := toCLIError(globalCfg, tt.err) - - if (err != nil) != tt.wantErr { - t.Errorf("toCLIError() error = %v, wantErr %v", err, tt.wantErr) - return - } - - if err != nil { - if exitErr, ok := err.(*errors.ExitError); ok { - if exitErr.ExitCode() != tt.wantCode { - t.Errorf("toCLIError() exit code = %v, want %v", exitErr.ExitCode(), tt.wantCode) - } - } else { - t.Errorf("toCLIError() returned non-ExitError: %T", err) - } - } - }) - } -} \ No newline at end of file