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
|
|
@ -36,6 +36,10 @@ func TestReadAllContext(t *testing.T) {
|
|||
if !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
var errWrapper *ErrWrapper
|
||||
if !errors.As(err, &errWrapper) {
|
||||
t.Fatal("the returned error is not wrapped")
|
||||
}
|
||||
if len(out) != 0 {
|
||||
t.Fatal("not the expected number of bytes")
|
||||
}
|
||||
|
|
@ -65,6 +69,10 @@ func TestReadAllContext(t *testing.T) {
|
|||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
var errWrapper *ErrWrapper
|
||||
if !errors.As(err, &errWrapper) {
|
||||
t.Fatal("the returned error is not wrapped")
|
||||
}
|
||||
if len(out) != 0 {
|
||||
t.Fatal("not the expected number of bytes")
|
||||
}
|
||||
|
|
@ -90,6 +98,10 @@ func TestReadAllContext(t *testing.T) {
|
|||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
var errWrapper *ErrWrapper
|
||||
if !errors.As(err, &errWrapper) {
|
||||
t.Fatal("the returned error is not wrapped")
|
||||
}
|
||||
if len(out) != 0 {
|
||||
t.Fatal("not the expected number of bytes")
|
||||
}
|
||||
|
|
@ -123,6 +135,10 @@ func TestCopyContext(t *testing.T) {
|
|||
if !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
var errWrapper *ErrWrapper
|
||||
if !errors.As(err, &errWrapper) {
|
||||
t.Fatal("the returned error is not wrapped")
|
||||
}
|
||||
if out != 0 {
|
||||
t.Fatal("not the expected number of bytes")
|
||||
}
|
||||
|
|
@ -152,6 +168,10 @@ func TestCopyContext(t *testing.T) {
|
|||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
var errWrapper *ErrWrapper
|
||||
if !errors.As(err, &errWrapper) {
|
||||
t.Fatal("the returned error is not wrapped")
|
||||
}
|
||||
if out != 0 {
|
||||
t.Fatal("not the expected number of bytes")
|
||||
}
|
||||
|
|
@ -177,6 +197,10 @@ func TestCopyContext(t *testing.T) {
|
|||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
var errWrapper *ErrWrapper
|
||||
if !errors.As(err, &errWrapper) {
|
||||
t.Fatal("the returned error is not wrapped")
|
||||
}
|
||||
if out != 0 {
|
||||
t.Fatal("not the expected number of bytes")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue