From ac88b74462ba6c8f720e6e6d182f93bdb74cc2f2 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 4 Aug 2025 11:15:35 +0200 Subject: [PATCH] cli-plugins/manager: wrapAsPluginError: don't special-case nil This was a pattern inheritted from pkg/errors.Wrapf, which ignored nil errors for convenience. However, it is error-prone, as it is not obvious when returning a nil-error. All call-sites using `wrapAsPluginError` already do a check for nil errors, so remove this code to prevent hard to find bugs. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 50963accec79a87652014d6b40a1d1cee4054f51) Signed-off-by: Sebastiaan van Stijn --- cli-plugins/manager/error.go | 3 --- cli-plugins/manager/error_test.go | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli-plugins/manager/error.go b/cli-plugins/manager/error.go index 7091491511..aaedae14fa 100644 --- a/cli-plugins/manager/error.go +++ b/cli-plugins/manager/error.go @@ -36,9 +36,6 @@ func (e *pluginError) MarshalText() (text []byte, err error) { // wrapAsPluginError wraps an error in a pluginError with an // additional message. func wrapAsPluginError(err error, msg string) error { - if err == nil { - return nil - } return &pluginError{cause: fmt.Errorf("%s: %w", msg, err)} } diff --git a/cli-plugins/manager/error_test.go b/cli-plugins/manager/error_test.go index 682860daad..2e92001c20 100644 --- a/cli-plugins/manager/error_test.go +++ b/cli-plugins/manager/error_test.go @@ -21,4 +21,7 @@ func TestPluginError(t *testing.T) { actual, err := json.Marshal(err) assert.Check(t, err) assert.Check(t, is.Equal(`"wrapping: testing"`, string(actual))) + + err = wrapAsPluginError(nil, "wrapping") + assert.Check(t, is.Error(err, "wrapping: %!w()")) }