From d00882aff2128382d72f66175b0564d04bfbab12 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 18 Feb 2026 23:41:48 +0100 Subject: [PATCH] api/types/jsonstream: prevent panic on nil-Error Signed-off-by: Sebastiaan van Stijn --- api/types/jsonstream/json_error.go | 3 +++ api/types/jsonstream/json_error_test.go | 10 ++++++++-- .../moby/moby/api/types/jsonstream/json_error.go | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/types/jsonstream/json_error.go b/api/types/jsonstream/json_error.go index 632b25fdf4..0dcc9337db 100644 --- a/api/types/jsonstream/json_error.go +++ b/api/types/jsonstream/json_error.go @@ -8,5 +8,8 @@ type Error struct { } func (e *Error) Error() string { + if e == nil { + return "" + } return e.Message } diff --git a/api/types/jsonstream/json_error_test.go b/api/types/jsonstream/json_error_test.go index 5f62df2741..a57af53928 100644 --- a/api/types/jsonstream/json_error_test.go +++ b/api/types/jsonstream/json_error_test.go @@ -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, "")) +} diff --git a/vendor/github.com/moby/moby/api/types/jsonstream/json_error.go b/vendor/github.com/moby/moby/api/types/jsonstream/json_error.go index 632b25fdf4..0dcc9337db 100644 --- a/vendor/github.com/moby/moby/api/types/jsonstream/json_error.go +++ b/vendor/github.com/moby/moby/api/types/jsonstream/json_error.go @@ -8,5 +8,8 @@ type Error struct { } func (e *Error) Error() string { + if e == nil { + return "" + } return e.Message }