mirror of
https://github.com/moby/moby.git
synced 2026-06-30 19:58:03 +00:00
api/types/jsonstream: prevent panic on nil-Error
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -8,5 +8,8 @@ type Error struct {
|
||||
}
|
||||
|
||||
func (e *Error) Error() string {
|
||||
if e == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return e.Message
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package jsonstream
|
||||
package jsonstream_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/types/jsonstream"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
|
||||
func TestError(t *testing.T) {
|
||||
je := Error{404, "Not found"}
|
||||
je := jsonstream.Error{Code: 404, Message: "Not found"}
|
||||
assert.Assert(t, is.Error(&je, "Not found"))
|
||||
}
|
||||
|
||||
func TestNilError(t *testing.T) {
|
||||
var je *jsonstream.Error
|
||||
assert.Assert(t, is.Error(je, "<nil>"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user