fix(netxlite): ensure HTTP errors are always wrapped (#584)
1. introduce implementations of HTTPTransport and HTTPClient that apply an error wrapping policy using the constructor for a generic top-level error wrapper 2. make sure we use the implementations in point 1 when we are constructing HTTPTransport and HTTPClient 3. make sure we apply error wrapping using the constructor for a generic top-level error wrapper when reading bodies 4. acknowledge that error wrapping would be broken if we do not return the same classification _and_ operation when we wrap an already wrapped error, so fix the to code to do that 5. acknowledge that the classifiers already deal with preserving the error string and explain why this is a quirk and why we cannot remove it right now and what needs to happen to safely remove this quirk from the codebase Closes https://github.com/ooni/probe/issues/1860
This commit is contained in:
parent
da34cfe6c9
commit
6a935d5407
9 changed files with 217 additions and 28 deletions
|
|
@ -3,6 +3,7 @@ package netxlite
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
|
|
@ -101,6 +102,22 @@ func TestNewErrWrapper(t *testing.T) {
|
|||
t.Fatal("unexpected WrappedErr")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("when the underlying error is already a wrapped error", func(t *testing.T) {
|
||||
ew := NewErrWrapper(classifySyscallError, ReadOperation, ECONNRESET)
|
||||
var err1 error = ew
|
||||
err2 := fmt.Errorf("cannot read: %w", err1)
|
||||
ew2 := NewErrWrapper(ClassifyGenericError, TopLevelOperation, err2)
|
||||
if ew2.Failure != ew.Failure {
|
||||
t.Fatal("not the same failure")
|
||||
}
|
||||
if ew2.Operation != ew.Operation {
|
||||
t.Fatal("not the same operation")
|
||||
}
|
||||
if ew2.WrappedErr != err2 {
|
||||
t.Fatal("invalid underlying error")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewTopLevelGenericErrWrapper(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue