fix(netxlite/errorsx): serialize directly to JSON (#491)
This simplifies serializing errors to `*string`. It did not occur to me before. It seems quite a nice improvement. Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
parent
957185d659
commit
18b2eb37ff
2 changed files with 23 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package errorsx
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
|
|
@ -23,4 +24,19 @@ func TestErrWrapper(t *testing.T) {
|
|||
t.Fatal("cannot unwrap error")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("MarshalJSON", func(t *testing.T) {
|
||||
wrappedErr := &ErrWrapper{
|
||||
Failure: FailureEOFError,
|
||||
WrappedErr: io.EOF,
|
||||
}
|
||||
data, err := json.Marshal(wrappedErr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := string(data)
|
||||
if s != "\""+FailureEOFError+"\"" {
|
||||
t.Fatal("invalid serialization", s)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue