Skip to content

Commit

Permalink
fix multi.Errors panic on nil append (#53)
Browse files Browse the repository at this point in the history
This extends the nil check for multi.Errors to the Append function to make sure
nil errors do not end up in the slice, causing a panic when the error string is
generated.

Signed-off-by: Jeremy Asher <[email protected]>
  • Loading branch information
jeremy-asher authored Feb 19, 2020
1 parent be7b275 commit ae164c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/common/errors/multi/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func Append(errs error, err error) error {
if !ok {
return New(errs, err)
}
if err == nil {
return errs
}
return append(m, err)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/common/errors/multi/multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func TestAppend(t *testing.T) {
assert.Equal(t, testErr, m1[0])
assert.Equal(t, testErr2, m1[1])

m = Append(Errors{testErr}, nil)
assert.Equal(t, Errors{testErr}, m)

m = Append(Errors{testErr}, testErr2)
m1, ok = m.(Errors)
assert.True(t, ok)
Expand Down

0 comments on commit ae164c9

Please sign in to comment.