From 7c60a784c16057b4cb0429ca9021e6f16d1d7f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 30 Jan 2023 17:39:53 +0100 Subject: [PATCH] Log data that we failed to unmarshal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should never happen with a consistent client/server, and we are seeing this show up with some hard-to-diagnose flakes. So, log details about failures. After we find the cause, we might remove this extra logging again. [NO NEW TESTS NEEDED] Signed-off-by: Miloslav Trmač --- pkg/bindings/errors.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/bindings/errors.go b/pkg/bindings/errors.go index d9dfa95a69..c1f1ed4639 100644 --- a/pkg/bindings/errors.go +++ b/pkg/bindings/errors.go @@ -15,7 +15,7 @@ var ( func handleError(data []byte, unmarshalErrorInto interface{}) error { if err := json.Unmarshal(data, unmarshalErrorInto); err != nil { - return err + return fmt.Errorf("unmarshaling error into %#v, data %q: %w", unmarshalErrorInto, string(data), err) } return unmarshalErrorInto.(error) } @@ -35,7 +35,10 @@ func (h APIResponse) ProcessWithError(unmarshalInto interface{}, unmarshalErrorI } if h.IsSuccess() || h.IsRedirection() { if unmarshalInto != nil { - return json.Unmarshal(data, unmarshalInto) + if err := json.Unmarshal(data, unmarshalInto); err != nil { + return fmt.Errorf("unmarshaling into %#v, data %q: %w", unmarshalInto, string(data), err) + } + return nil } return nil }