-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
If the writer encounters an error the error is stored in the encoder, but it is not returned.
Line 537 in 3055897
if _, err := enc.writer.Write(b); err != nil { |
This is because the above line is creating a new err variable due to the :
in the assignment.
This test code demonstrates the issue:
type errWriter struct{}
func (ew *errWriter) Write([]byte) (n int, err error) {
return 0, errors.New("test-error")
}
func TestWriterErr(t *testing.T) {
t.Parallel()
enc := NewEncoder(&errWriter{})
err := enc.Encode("")
if err == nil {
t.Error("expected error not returned")
} else if err.Error() != "test-error" {
t.Errorf("unexpected error returned: want=test-error got=%s", err.Error())
}
}
Metadata
Metadata
Assignees
Labels
No labels