Log data that we failed to unmarshal

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č <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač
2023-01-30 17:39:53 +01:00
parent 929d03a5ea
commit 7c60a784c1

@ -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
}