refactor: move i/e/n/errorx to i/errorsx (#416)

Still working towards https://github.com/ooni/probe/issues/1505
This commit is contained in:
Simone Basso
2021-07-01 16:34:36 +02:00
committed by GitHub
parent 6895946a34
commit 72acd175a0
58 changed files with 287 additions and 287 deletions
+4 -4
View File
@@ -8,7 +8,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/handlers"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/oldhttptransport"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
"github.com/ooni/probe-cli/v3/internal/errorsx"
"golang.org/x/net/http2"
)
@@ -81,10 +81,10 @@ func (t *HTTPTransport) RoundTrip(
resp, err = t.roundTripper.RoundTrip(req)
// For safety wrap the error as modelx.HTTPRoundTripOperation but this
// will only be used if the error chain does not contain any
// other major operation failure. See errorx.ErrWrapper.
err = errorx.SafeErrWrapperBuilder{
// other major operation failure. See errorsx.ErrWrapper.
err = errorsx.SafeErrWrapperBuilder{
Error: err,
Operation: errorx.HTTPRoundTripOperation,
Operation: errorsx.HTTPRoundTripOperation,
}.MaybeBuild()
return resp, err
}
+2 -2
View File
@@ -13,7 +13,7 @@ import (
"time"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
"github.com/ooni/probe-cli/v3/internal/errorsx"
"github.com/ooni/probe-cli/v3/internal/iox"
)
@@ -148,7 +148,7 @@ func TestHTTPTransportTimeout(t *testing.T) {
if err == nil {
t.Fatal("expected an error here")
}
if !strings.HasSuffix(err.Error(), errorx.FailureGenericTimeoutError) {
if !strings.HasSuffix(err.Error(), errorsx.FailureGenericTimeoutError) {
t.Fatal("not the error we expected")
}
if resp != nil {
@@ -8,7 +8,7 @@ import (
"testing"
"time"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
"github.com/ooni/probe-cli/v3/internal/errorsx"
)
func TestNewTLSConnectionState(t *testing.T) {
@@ -61,7 +61,7 @@ func TestMeasurementRootWithMeasurementRootPanic(t *testing.T) {
func TestErrWrapperPublicAPI(t *testing.T) {
child := errors.New("mocked error")
wrapper := &errorx.ErrWrapper{
wrapper := &errorsx.ErrWrapper{
Failure: "moobar",
WrappedErr: child,
}
@@ -12,7 +12,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
"github.com/ooni/probe-cli/v3/internal/errorsx"
"github.com/ooni/probe-cli/v3/internal/iox"
)
@@ -83,7 +83,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) {
var (
err error
majorOp = errorx.HTTPRoundTripOperation
majorOp = errorsx.HTTPRoundTripOperation
majorOpMu sync.Mutex
requestBody []byte
requestHeaders = http.Header{}
@@ -103,7 +103,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) {
tracer := &httptrace.ClientTrace{
TLSHandshakeStart: func() {
majorOpMu.Lock()
majorOp = errorx.TLSHandshakeOperation
majorOp = errorsx.TLSHandshakeOperation
majorOpMu.Unlock()
// Event emitted by net/http when DialTLS is not
// configured in the http.Transport
@@ -116,9 +116,9 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) {
TLSHandshakeDone: func(state tls.ConnectionState, err error) {
// Wrapping the error even if we're not returning it because it may
// less confusing to users to see the wrapped name
err = errorx.SafeErrWrapperBuilder{
err = errorsx.SafeErrWrapperBuilder{
Error: err,
Operation: errorx.TLSHandshakeOperation,
Operation: errorsx.TLSHandshakeOperation,
}.MaybeBuild()
durationSinceBeginning := time.Since(root.Beginning)
// Event emitted by net/http when DialTLS is not
@@ -133,7 +133,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) {
},
GotConn: func(info httptrace.GotConnInfo) {
majorOpMu.Lock()
majorOp = errorx.HTTPRoundTripOperation
majorOp = errorsx.HTTPRoundTripOperation
majorOpMu.Unlock()
root.Handler.OnMeasurement(modelx.Measurement{
HTTPConnectionReady: &modelx.HTTPConnectionReadyEvent{
@@ -171,9 +171,9 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) {
WroteRequest: func(info httptrace.WroteRequestInfo) {
// Wrapping the error even if we're not returning it because it may
// less confusing to users to see the wrapped name
err := errorx.SafeErrWrapperBuilder{
err := errorsx.SafeErrWrapperBuilder{
Error: info.Err,
Operation: errorx.HTTPRoundTripOperation,
Operation: errorsx.HTTPRoundTripOperation,
}.MaybeBuild()
root.Handler.OnMeasurement(modelx.Measurement{
HTTPRequestDone: &modelx.HTTPRequestDoneEvent{
@@ -207,7 +207,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) {
}
resp, err := t.roundTripper.RoundTrip(req)
err = errorx.SafeErrWrapperBuilder{
err = errorsx.SafeErrWrapperBuilder{
Error: err,
Operation: majorOp,
}.MaybeBuild()
@@ -19,7 +19,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
"github.com/ooni/probe-cli/v3/internal/errorsx"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -418,7 +418,7 @@ func NewNetworkEventsList(results oonitemplates.Results) NetworkEventsList {
out = append(out, &NetworkEvent{
Address: in.Connect.RemoteAddress,
Failure: makeFailure(in.Connect.Error),
Operation: errorx.ConnectOperation,
Operation: errorsx.ConnectOperation,
T: in.Connect.DurationSinceBeginning.Seconds(),
})
// fallthrough
@@ -426,7 +426,7 @@ func NewNetworkEventsList(results oonitemplates.Results) NetworkEventsList {
if in.Read != nil {
out = append(out, &NetworkEvent{
Failure: makeFailure(in.Read.Error),
Operation: errorx.ReadOperation,
Operation: errorsx.ReadOperation,
NumBytes: in.Read.NumBytes,
T: in.Read.DurationSinceBeginning.Seconds(),
})
@@ -435,7 +435,7 @@ func NewNetworkEventsList(results oonitemplates.Results) NetworkEventsList {
if in.Write != nil {
out = append(out, &NetworkEvent{
Failure: makeFailure(in.Write.Error),
Operation: errorx.WriteOperation,
Operation: errorsx.WriteOperation,
NumBytes: in.Write.NumBytes,
T: in.Write.DurationSinceBeginning.Seconds(),
})
@@ -12,7 +12,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
"github.com/ooni/probe-cli/v3/internal/errorsx"
)
func TestNewTCPConnectListEmpty(t *testing.T) {
@@ -67,7 +67,7 @@ func TestNewTCPConnectListFailure(t *testing.T) {
Connects: []*modelx.ConnectEvent{
{
RemoteAddress: "8.8.8.8:53",
Error: errors.New(errorx.FailureConnectionReset),
Error: errors.New(errorsx.FailureConnectionReset),
},
},
})
@@ -80,7 +80,7 @@ func TestNewTCPConnectListFailure(t *testing.T) {
if out[0].Port != 53 {
t.Fatal("unexpected out[0].Port")
}
if *out[0].Status.Failure != errorx.FailureConnectionReset {
if *out[0].Status.Failure != errorsx.FailureConnectionReset {
t.Fatal("unexpected out[0].Failure")
}
if out[0].Status.Success != false {
@@ -93,7 +93,7 @@ func TestNewTCPConnectListInvalidInput(t *testing.T) {
Connects: []*modelx.ConnectEvent{
{
RemoteAddress: "8.8.8.8",
Error: errors.New(errorx.FailureConnectionReset),
Error: errors.New(errorsx.FailureConnectionReset),
},
},
})
@@ -106,7 +106,7 @@ func TestNewTCPConnectListInvalidInput(t *testing.T) {
if out[0].Port != 0 {
t.Fatal("unexpected out[0].Port")
}
if *out[0].Status.Failure != errorx.FailureConnectionReset {
if *out[0].Status.Failure != errorsx.FailureConnectionReset {
t.Fatal("unexpected out[0].Failure")
}
if out[0].Status.Success != false {
@@ -649,7 +649,7 @@ func TestNewDNSQueriesListSuccess(t *testing.T) {
TransportNetwork: "system",
},
{
Error: errors.New(errorx.FailureDNSNXDOMAINError),
Error: errors.New(errorsx.FailureDNSNXDOMAINError),
Hostname: "dns.googlex",
TransportNetwork: "system",
},
@@ -768,7 +768,7 @@ func dnscheckbad(e DNSQueryEntry) error {
if e.Engine != "system" {
return errors.New("invalid engine")
}
if *e.Failure != errorx.FailureDNSNXDOMAINError {
if *e.Failure != errorsx.FailureDNSNXDOMAINError {
return errors.New("invalid failure")
}
if e.Hostname != "dns.googlex" {
@@ -854,7 +854,7 @@ func TestNewNetworkEventsListGood(t *testing.T) {
if out[0].NumBytes != 0 {
t.Fatal("wrong out[0].NumBytes")
}
if out[0].Operation != errorx.ConnectOperation {
if out[0].Operation != errorsx.ConnectOperation {
t.Fatal("wrong out[0].Operation")
}
if !floatEquals(out[0].T, 0.010) {
@@ -870,7 +870,7 @@ func TestNewNetworkEventsListGood(t *testing.T) {
if out[1].NumBytes != 1789 {
t.Fatal("wrong out[1].NumBytes")
}
if out[1].Operation != errorx.ReadOperation {
if out[1].Operation != errorsx.ReadOperation {
t.Fatal("wrong out[1].Operation")
}
if !floatEquals(out[1].T, 0.020) {
@@ -886,7 +886,7 @@ func TestNewNetworkEventsListGood(t *testing.T) {
if out[2].NumBytes != 17714 {
t.Fatal("wrong out[2].NumBytes")
}
if out[2].Operation != errorx.WriteOperation {
if out[2].Operation != errorsx.WriteOperation {
t.Fatal("wrong out[2].Operation")
}
if !floatEquals(out[2].T, 0.030) {
@@ -933,7 +933,7 @@ func TestNewNetworkEventsListGoodUDPAndErrors(t *testing.T) {
if out[0].NumBytes != 0 {
t.Fatal("wrong out[0].NumBytes")
}
if out[0].Operation != errorx.ConnectOperation {
if out[0].Operation != errorsx.ConnectOperation {
t.Fatal("wrong out[0].Operation")
}
if !floatEquals(out[0].T, 0.010) {
@@ -949,7 +949,7 @@ func TestNewNetworkEventsListGoodUDPAndErrors(t *testing.T) {
if out[1].NumBytes != 1789 {
t.Fatal("wrong out[1].NumBytes")
}
if out[1].Operation != errorx.ReadOperation {
if out[1].Operation != errorsx.ReadOperation {
t.Fatal("wrong out[1].Operation")
}
if !floatEquals(out[1].T, 0.020) {
@@ -965,7 +965,7 @@ func TestNewNetworkEventsListGoodUDPAndErrors(t *testing.T) {
if out[2].NumBytes != 17714 {
t.Fatal("wrong out[2].NumBytes")
}
if out[2].Operation != errorx.WriteOperation {
if out[2].Operation != errorsx.WriteOperation {
t.Fatal("wrong out[2].Operation")
}
if !floatEquals(out[2].T, 0.030) {
@@ -11,7 +11,7 @@ import (
goptlib "git.torproject.org/pluggable-transports/goptlib.git"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
"github.com/ooni/probe-cli/v3/internal/errorsx"
"gitlab.com/yawning/obfs4.git/transports"
obfs4base "gitlab.com/yawning/obfs4.git/transports/base"
)
@@ -55,7 +55,7 @@ func TestDNSLookupCancellation(t *testing.T) {
if results.Error == nil {
t.Fatal("expected an error here")
}
if results.Error.Error() != errorx.FailureGenericTimeoutError {
if results.Error.Error() != errorsx.FailureGenericTimeoutError {
t.Fatal("not the error we expected")
}
if len(results.Addresses) > 0 {
@@ -170,7 +170,7 @@ func TestTLSConnectCancellation(t *testing.T) {
if results.Error == nil {
t.Fatal("expected an error here")
}
if results.Error.Error() != errorx.FailureGenericTimeoutError {
if results.Error.Error() != errorsx.FailureGenericTimeoutError {
t.Fatal("not the error we expected")
}
}