Skip to content

Commit 50963ac

Browse files
committed
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 <[email protected]>
1 parent d789bac commit 50963ac

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

cli-plugins/manager/error.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ func (e *pluginError) MarshalText() (text []byte, err error) {
3636
// wrapAsPluginError wraps an error in a pluginError with an
3737
// additional message.
3838
func wrapAsPluginError(err error, msg string) error {
39-
if err == nil {
40-
return nil
41-
}
4239
return &pluginError{cause: fmt.Errorf("%s: %w", msg, err)}
4340
}
4441

cli-plugins/manager/error_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ func TestPluginError(t *testing.T) {
2121
actual, err := json.Marshal(err)
2222
assert.Check(t, err)
2323
assert.Check(t, is.Equal(`"wrapping: testing"`, string(actual)))
24+
25+
err = wrapAsPluginError(nil, "wrapping")
26+
assert.Check(t, is.Error(err, "wrapping: %!w(<nil>)"))
2427
}

0 commit comments

Comments
 (0)