From 72acd175a0d997fba3800e69d3342bc2d12e2864 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 1 Jul 2021 16:34:36 +0200 Subject: [PATCH] refactor: move i/e/n/errorx to i/errorsx (#416) Still working towards https://github.com/ooni/probe/issues/1505 --- internal/engine/experiment/dash/dash.go | 4 +- internal/engine/experiment/dash/dash_test.go | 6 +- .../experiment/fbmessenger/fbmessenger.go | 6 +- .../fbmessenger/fbmessenger_test.go | 6 +- internal/engine/experiment/hhfm/hhfm.go | 8 +-- internal/engine/experiment/hhfm/hhfm_test.go | 8 +-- internal/engine/experiment/hirl/hirl.go | 4 +- internal/engine/experiment/hirl/hirl_test.go | 4 +- .../experiment/riseupvpn/riseupvpn_test.go | 10 +-- .../engine/experiment/signal/signal_test.go | 6 +- .../experiment/sniblocking/sniblocking.go | 22 +++--- .../sniblocking/sniblocking_test.go | 32 ++++----- .../stunreachability/stunreachability.go | 4 +- .../stunreachability/stunreachability_test.go | 4 +- .../engine/experiment/telegram/telegram.go | 4 +- .../experiment/telegram/telegram_test.go | 30 ++++---- internal/engine/experiment/tor/tor.go | 4 +- internal/engine/experiment/tor/tor_test.go | 8 +-- .../engine/experiment/urlgetter/getter.go | 6 +- .../urlgetter/getter_integration_test.go | 20 +++--- .../engine/experiment/urlgetter/runner.go | 6 +- .../experiment/webconnectivity/control.go | 6 +- .../experiment/webconnectivity/dnsanalysis.go | 4 +- .../webconnectivity/dnsanalysis_test.go | 4 +- .../experiment/webconnectivity/summary.go | 22 +++--- .../webconnectivity/summary_test.go | 18 ++--- .../webconnectivity/webconnectivity_test.go | 6 +- internal/engine/legacy/netx/http.go | 8 +-- internal/engine/legacy/netx/http_test.go | 4 +- .../engine/legacy/netx/modelx/modelx_test.go | 4 +- .../netx/oldhttptransport/tracetripper.go | 18 ++--- .../legacy/oonidatamodel/oonidatamodel.go | 8 +-- .../oonidatamodel/oonidatamodel_test.go | 26 +++---- .../oonitemplates/oonitemplates_test.go | 6 +- internal/engine/netx/archival/archival.go | 24 +++---- .../engine/netx/archival/archival_test.go | 68 +++++++++---------- internal/engine/netx/dialer/errorwrapper.go | 18 ++--- .../engine/netx/dialer/errorwrapper_test.go | 14 ++-- internal/engine/netx/dialer/saver.go | 8 +-- internal/engine/netx/dialer/saver_test.go | 4 +- internal/engine/netx/integration_test.go | 6 +- .../engine/netx/quicdialer/errorwrapper.go | 8 +-- .../netx/quicdialer/errorwrapper_test.go | 10 +-- internal/engine/netx/quicdialer/system.go | 6 +- .../engine/netx/quicdialer/system_test.go | 4 +- internal/engine/netx/resolver/bogon.go | 4 +- internal/engine/netx/resolver/bogon_test.go | 4 +- internal/engine/netx/resolver/errorwrapper.go | 8 +-- .../engine/netx/resolver/errorwrapper_test.go | 8 +-- internal/engine/netx/tlsdialer/saver_test.go | 4 +- internal/engine/netx/tlsdialer/tls.go | 8 +-- internal/engine/netx/tlsdialer/tls_test.go | 8 +-- .../netx/errorx => errorsx}/errno_unix.go | 2 +- .../netx/errorx => errorsx}/errno_windows.go | 2 +- .../errorx/errorx.go => errorsx/errorsx.go} | 4 +- .../errorsx_test.go} | 2 +- internal/netxlite/legacy.go | 4 +- internal/netxlite/legacy_test.go | 10 +-- 58 files changed, 287 insertions(+), 287 deletions(-) rename internal/{engine/netx/errorx => errorsx}/errno_unix.go (98%) rename internal/{engine/netx/errorx => errorsx}/errno_windows.go (98%) rename internal/{engine/netx/errorx/errorx.go => errorsx/errorsx.go} (99%) rename internal/{engine/netx/errorx/errorx_test.go => errorsx/errorsx_test.go} (99%) diff --git a/internal/engine/experiment/dash/dash.go b/internal/engine/experiment/dash/dash.go index 08313b3..4cb6869 100644 --- a/internal/engine/experiment/dash/dash.go +++ b/internal/engine/experiment/dash/dash.go @@ -16,8 +16,8 @@ import ( "github.com/montanaflynn/stats" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" "github.com/ooni/probe-cli/v3/internal/humanize" "github.com/ooni/probe-cli/v3/internal/iox" ) @@ -172,7 +172,7 @@ func (r runner) measure( // of the latest connect time. We should have one sample in most // cases, because the connection should be persistent. for _, ev := range r.saver.Read() { - if ev.Name == errorx.ConnectOperation { + if ev.Name == errorsx.ConnectOperation { connectTime = ev.Duration.Seconds() } } diff --git a/internal/engine/experiment/dash/dash_test.go b/internal/engine/experiment/dash/dash_test.go index bad2c81..7376005 100644 --- a/internal/engine/experiment/dash/dash_test.go +++ b/internal/engine/experiment/dash/dash_test.go @@ -13,8 +13,8 @@ import ( "github.com/montanaflynn/stats" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestRunnerLoopLocateFailure(t *testing.T) { @@ -108,7 +108,7 @@ func TestRunnerLoopMeasureFailure(t *testing.T) { func TestRunnerLoopCollectFailure(t *testing.T) { expected := errors.New("mocked error") saver := new(trace.Saver) - saver.Write(trace.Event{Name: errorx.ConnectOperation, Duration: 150 * time.Millisecond}) + saver.Write(trace.Event{Name: errorsx.ConnectOperation, Duration: 150 * time.Millisecond}) r := runner{ callbacks: model.NewPrinterCallbacks(log.Log), httpClient: &http.Client{ @@ -152,7 +152,7 @@ func TestRunnerLoopCollectFailure(t *testing.T) { func TestRunnerLoopSuccess(t *testing.T) { saver := new(trace.Saver) - saver.Write(trace.Event{Name: errorx.ConnectOperation, Duration: 150 * time.Millisecond}) + saver.Write(trace.Event{Name: errorsx.ConnectOperation, Duration: 150 * time.Millisecond}) r := runner{ callbacks: model.NewPrinterCallbacks(log.Log), httpClient: &http.Client{ diff --git a/internal/engine/experiment/fbmessenger/fbmessenger.go b/internal/engine/experiment/fbmessenger/fbmessenger.go index 77e3c2f..ec13b96 100644 --- a/internal/engine/experiment/fbmessenger/fbmessenger.go +++ b/internal/engine/experiment/fbmessenger/fbmessenger.go @@ -11,7 +11,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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" ) const ( @@ -111,7 +111,7 @@ func (tk *TestKeys) ComputeEndpointStatus(v urlgetter.MultiOutput, dns, tcp **bo // start where all is unknown *dns, *tcp = nil, nil // process DNS first - if v.TestKeys.FailedOperation != nil && *v.TestKeys.FailedOperation == errorx.ResolveOperation { + if v.TestKeys.FailedOperation != nil && *v.TestKeys.FailedOperation == errorsx.ResolveOperation { tk.FacebookDNSBlocking = &trueValue *dns = &falseValue return // we know that the DNS has failed @@ -127,7 +127,7 @@ func (tk *TestKeys) ComputeEndpointStatus(v urlgetter.MultiOutput, dns, tcp **bo } *dns = &trueValue // now process connect - if v.TestKeys.FailedOperation != nil && *v.TestKeys.FailedOperation == errorx.ConnectOperation { + if v.TestKeys.FailedOperation != nil && *v.TestKeys.FailedOperation == errorsx.ConnectOperation { tk.FacebookTCPBlocking = &trueValue *tcp = &falseValue return // because connect failed diff --git a/internal/engine/experiment/fbmessenger/fbmessenger_test.go b/internal/engine/experiment/fbmessenger/fbmessenger_test.go index 992d6e3..2fba4fe 100644 --- a/internal/engine/experiment/fbmessenger/fbmessenger_test.go +++ b/internal/engine/experiment/fbmessenger/fbmessenger_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/mockable" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestNewExperimentMeasurer(t *testing.T) { @@ -162,7 +162,7 @@ func TestWithCancelledContext(t *testing.T) { func TestComputeEndpointStatsTCPBlocking(t *testing.T) { failure := io.EOF.Error() - operation := errorx.ConnectOperation + operation := errorsx.ConnectOperation tk := fbmessenger.TestKeys{} tk.Update(urlgetter.MultiOutput{ Input: urlgetter.MultiInput{Target: fbmessenger.ServiceEdge}, @@ -192,7 +192,7 @@ func TestComputeEndpointStatsTCPBlocking(t *testing.T) { func TestComputeEndpointStatsDNSIsLying(t *testing.T) { failure := io.EOF.Error() - operation := errorx.ConnectOperation + operation := errorsx.ConnectOperation tk := fbmessenger.TestKeys{} tk.Update(urlgetter.MultiOutput{ Input: urlgetter.MultiInput{Target: fbmessenger.ServiceEdge}, diff --git a/internal/engine/experiment/hhfm/hhfm.go b/internal/engine/experiment/hhfm/hhfm.go index d6b69e0..3283c63 100644 --- a/internal/engine/experiment/hhfm/hhfm.go +++ b/internal/engine/experiment/hhfm/hhfm.go @@ -19,7 +19,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" "github.com/ooni/probe-cli/v3/internal/engine/netx/dialer" - "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" "github.com/ooni/probe-cli/v3/internal/randx" ) @@ -164,7 +164,7 @@ func (m Measurer) Run( // parse response body var jsonHeaders JSONHeaders if err := json.Unmarshal(data, &jsonHeaders); err != nil { - failure := errorx.FailureJSONParseError + failure := errorsx.FailureJSONParseError tk.Failure = &failure tk.Tampering.Total = true return nil // measurement did not fail, we measured tampering @@ -180,8 +180,8 @@ func Transact(txp Transport, req *http.Request, callbacks model.ExperimentCallbacks) (*http.Response, []byte, error) { // make sure that we return a wrapped error here resp, data, err := transact(txp, req, callbacks) - err = errorx.SafeErrWrapperBuilder{ - Error: err, Operation: errorx.TopLevelOperation}.MaybeBuild() + err = errorsx.SafeErrWrapperBuilder{ + Error: err, Operation: errorsx.TopLevelOperation}.MaybeBuild() return resp, data, err } diff --git a/internal/engine/experiment/hhfm/hhfm_test.go b/internal/engine/experiment/hhfm/hhfm_test.go index 3a5ca87..24502db 100644 --- a/internal/engine/experiment/hhfm/hhfm_test.go +++ b/internal/engine/experiment/hhfm/hhfm_test.go @@ -18,7 +18,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/mockable" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestNewExperimentMeasurer(t *testing.T) { @@ -161,14 +161,14 @@ func TestCancelledContext(t *testing.T) { if tk.Agent != "agent" { t.Fatal("invalid Agent") } - if *tk.Failure != errorx.FailureInterrupted { + if *tk.Failure != errorsx.FailureInterrupted { t.Fatal("invalid Failure") } if len(tk.Requests) != 1 { t.Fatal("invalid Requests") } request := tk.Requests[0] - if *request.Failure != errorx.FailureInterrupted { + if *request.Failure != errorsx.FailureInterrupted { t.Fatal("invalid Requests[0].Failure") } if request.Request.Body.Value != "" { @@ -480,7 +480,7 @@ func TestInvalidJSONBody(t *testing.T) { if tk.Agent != "agent" { t.Fatal("invalid Agent") } - if *tk.Failure != errorx.FailureJSONParseError { + if *tk.Failure != errorsx.FailureJSONParseError { t.Fatal("invalid Failure") } if len(tk.Requests) != 1 { diff --git a/internal/engine/experiment/hirl/hirl.go b/internal/engine/experiment/hirl/hirl.go index 5d7c47e..dc07730 100644 --- a/internal/engine/experiment/hirl/hirl.go +++ b/internal/engine/experiment/hirl/hirl.go @@ -14,7 +14,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "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/randx" ) @@ -293,7 +293,7 @@ func RunMethod(ctx context.Context, config RunMethodConfig) { count, err := conn.Read(data) if err != nil { // We expect this method to terminate w/ timeout - if err.Error() == errorx.FailureGenericTimeoutError { + if err.Error() == errorsx.FailureGenericTimeoutError { err = nil } result.Err = err diff --git a/internal/engine/experiment/hirl/hirl_test.go b/internal/engine/experiment/hirl/hirl_test.go index eda81b0..e0bf183 100644 --- a/internal/engine/experiment/hirl/hirl_test.go +++ b/internal/engine/experiment/hirl/hirl_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestNewExperimentMeasurer(t *testing.T) { @@ -97,7 +97,7 @@ func TestCancelledContext(t *testing.T) { t.Fatal("unexpected FailureList length") } for _, failure := range tk.FailureList { - if *failure != errorx.FailureInterrupted { + if *failure != errorsx.FailureInterrupted { t.Fatal("unexpected failure") } } diff --git a/internal/engine/experiment/riseupvpn/riseupvpn_test.go b/internal/engine/experiment/riseupvpn/riseupvpn_test.go index 5e9a786..e1672a7 100644 --- a/internal/engine/experiment/riseupvpn/riseupvpn_test.go +++ b/internal/engine/experiment/riseupvpn/riseupvpn_test.go @@ -17,7 +17,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/mockable" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) const ( @@ -270,11 +270,11 @@ func TestUpdateWithMixedResults(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorx.HTTPRoundTripOperation + s := errorsx.HTTPRoundTripOperation return &s })(), Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -291,7 +291,7 @@ func TestUpdateWithMixedResults(t *testing.T) { if tk.APIStatus != "blocked" { t.Fatal("ApiStatus should be blocked") } - if *tk.APIFailure != errorx.FailureEOFError { + if *tk.APIFailure != errorsx.FailureEOFError { t.Fatal("invalid ApiFailure") } if tk.FailingGateways != nil { @@ -730,7 +730,7 @@ func generateMockGetter(requestResponse map[string]string, responseStatus map[st responseBody = "" eofError := io.EOF.Error() failure = &eofError - connectOperation := errorx.ConnectOperation + connectOperation := errorsx.ConnectOperation failedOperation = &connectOperation responseStatus = 0 } diff --git a/internal/engine/experiment/signal/signal_test.go b/internal/engine/experiment/signal/signal_test.go index 211232e..ee2e19f 100644 --- a/internal/engine/experiment/signal/signal_test.go +++ b/internal/engine/experiment/signal/signal_test.go @@ -9,7 +9,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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" ) func TestNewExperimentMeasurer(t *testing.T) { @@ -85,7 +85,7 @@ func TestUpdate(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -93,7 +93,7 @@ func TestUpdate(t *testing.T) { if tk.SignalBackendStatus != "blocked" { t.Fatal("SignalBackendStatus should be blocked") } - if *tk.SignalBackendFailure != errorx.FailureEOFError { + if *tk.SignalBackendFailure != errorsx.FailureEOFError { t.Fatal("invalid SignalBackendError") } } diff --git a/internal/engine/experiment/sniblocking/sniblocking.go b/internal/engine/experiment/sniblocking/sniblocking.go index dee06a0..4c4af64 100644 --- a/internal/engine/experiment/sniblocking/sniblocking.go +++ b/internal/engine/experiment/sniblocking/sniblocking.go @@ -15,7 +15,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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" ) const ( @@ -64,24 +64,24 @@ func (tk *TestKeys) classify() string { return classSuccessGotServerHello } switch *tk.Target.Failure { - case errorx.FailureConnectionRefused: + case errorsx.FailureConnectionRefused: return classAnomalyTestHelperUnreachable - case errorx.FailureConnectionReset: + case errorsx.FailureConnectionReset: return classInterferenceReset - case errorx.FailureDNSNXDOMAINError: + case errorsx.FailureDNSNXDOMAINError: return classAnomalyTestHelperUnreachable - case errorx.FailureEOFError: + case errorsx.FailureEOFError: return classInterferenceClosed - case errorx.FailureGenericTimeoutError: + case errorsx.FailureGenericTimeoutError: if tk.Control.Failure != nil { return classAnomalyTestHelperUnreachable } return classAnomalyTimeout - case errorx.FailureSSLInvalidCertificate: + case errorsx.FailureSSLInvalidCertificate: return classInterferenceInvalidCertificate - case errorx.FailureSSLInvalidHostname: + case errorsx.FailureSSLInvalidHostname: return classSuccessGotServerHello - case errorx.FailureSSLUnknownAuthority: + case errorsx.FailureSSLUnknownAuthority: return classInterferenceUnknownAuthority } return classAnomalyUnexpectedFailure @@ -117,8 +117,8 @@ func (m *Measurer) measureone( select { case <-time.After(sleeptime): case <-ctx.Done(): - s := errorx.FailureInterrupted - failedop := errorx.TopLevelOperation + s := errorsx.FailureInterrupted + failedop := errorsx.TopLevelOperation return Subresult{ TestKeys: urlgetter.TestKeys{ FailedOperation: &failedop, diff --git a/internal/engine/experiment/sniblocking/sniblocking_test.go b/internal/engine/experiment/sniblocking/sniblocking_test.go index eb8390c..078b7ed 100644 --- a/internal/engine/experiment/sniblocking/sniblocking_test.go +++ b/internal/engine/experiment/sniblocking/sniblocking_test.go @@ -9,7 +9,7 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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" ) const ( @@ -29,64 +29,64 @@ func TestTestKeysClassify(t *testing.T) { }) t.Run("with tk.Target.Failure == connection_refused", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorx.FailureConnectionRefused) + tk.Target.Failure = asStringPtr(errorsx.FailureConnectionRefused) if tk.classify() != classAnomalyTestHelperUnreachable { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == dns_nxdomain_error", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorx.FailureDNSNXDOMAINError) + tk.Target.Failure = asStringPtr(errorsx.FailureDNSNXDOMAINError) if tk.classify() != classAnomalyTestHelperUnreachable { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == connection_reset", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorx.FailureConnectionReset) + tk.Target.Failure = asStringPtr(errorsx.FailureConnectionReset) if tk.classify() != classInterferenceReset { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == eof_error", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorx.FailureEOFError) + tk.Target.Failure = asStringPtr(errorsx.FailureEOFError) if tk.classify() != classInterferenceClosed { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == ssl_invalid_hostname", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorx.FailureSSLInvalidHostname) + tk.Target.Failure = asStringPtr(errorsx.FailureSSLInvalidHostname) if tk.classify() != classSuccessGotServerHello { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == ssl_unknown_authority", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorx.FailureSSLUnknownAuthority) + tk.Target.Failure = asStringPtr(errorsx.FailureSSLUnknownAuthority) if tk.classify() != classInterferenceUnknownAuthority { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == ssl_invalid_certificate", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorx.FailureSSLInvalidCertificate) + tk.Target.Failure = asStringPtr(errorsx.FailureSSLInvalidCertificate) if tk.classify() != classInterferenceInvalidCertificate { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == generic_timeout_error #1", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorx.FailureGenericTimeoutError) + tk.Target.Failure = asStringPtr(errorsx.FailureGenericTimeoutError) if tk.classify() != classAnomalyTimeout { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == generic_timeout_error #2", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorx.FailureGenericTimeoutError) - tk.Control.Failure = asStringPtr(errorx.FailureGenericTimeoutError) + tk.Target.Failure = asStringPtr(errorsx.FailureGenericTimeoutError) + tk.Control.Failure = asStringPtr(errorsx.FailureGenericTimeoutError) if tk.classify() != classAnomalyTestHelperUnreachable { t.Fatal("unexpected result") } @@ -191,10 +191,10 @@ func TestMeasureoneCancelledContext(t *testing.T) { if result.DNSCache != nil { t.Fatal("not the expected DNSCache") } - if result.FailedOperation == nil || *result.FailedOperation != errorx.TopLevelOperation { + if result.FailedOperation == nil || *result.FailedOperation != errorsx.TopLevelOperation { t.Fatal("not the expected FailedOperation") } - if result.Failure == nil || *result.Failure != errorx.FailureInterrupted { + if result.Failure == nil || *result.Failure != errorsx.FailureInterrupted { t.Fatal("not the expected failure") } if result.NetworkEvents != nil { @@ -295,10 +295,10 @@ func TestMeasureoneSuccess(t *testing.T) { if result.DNSCache != nil { t.Fatal("not the expected DNSCache") } - if result.FailedOperation == nil || *result.FailedOperation != errorx.TLSHandshakeOperation { + if result.FailedOperation == nil || *result.FailedOperation != errorsx.TLSHandshakeOperation { t.Fatal("not the expected FailedOperation") } - if result.Failure == nil || *result.Failure != errorx.FailureSSLInvalidHostname { + if result.Failure == nil || *result.Failure != errorsx.FailureSSLInvalidHostname { t.Fatal("unexpected failure") } if len(result.NetworkEvents) < 1 { @@ -348,7 +348,7 @@ func TestMeasureonewithcacheWorks(t *testing.T) { if result.Cached != expected { t.Fatal("unexpected cached") } - if *result.Failure != errorx.FailureSSLInvalidHostname { + if *result.Failure != errorsx.FailureSSLInvalidHostname { t.Fatal("unexpected failure") } if result.SNI != "kernel.org" { diff --git a/internal/engine/experiment/stunreachability/stunreachability.go b/internal/engine/experiment/stunreachability/stunreachability.go index b4b2211..81f710a 100644 --- a/internal/engine/experiment/stunreachability/stunreachability.go +++ b/internal/engine/experiment/stunreachability/stunreachability.go @@ -13,8 +13,8 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" "github.com/ooni/probe-cli/v3/internal/engine/netx/dialer" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" "github.com/pion/stun" ) @@ -58,7 +58,7 @@ func (m *Measurer) ExperimentVersion() string { } func wrap(err error) error { - return errorx.SafeErrWrapperBuilder{ + return errorsx.SafeErrWrapperBuilder{ Error: err, Operation: "stun", }.MaybeBuild() diff --git a/internal/engine/experiment/stunreachability/stunreachability_test.go b/internal/engine/experiment/stunreachability/stunreachability_test.go index 8ce0c84..fe260cb 100644 --- a/internal/engine/experiment/stunreachability/stunreachability_test.go +++ b/internal/engine/experiment/stunreachability/stunreachability_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/stunreachability" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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/pion/stun" ) @@ -213,7 +213,7 @@ func TestReadFailure(t *testing.T) { t.Fatal("not the error we expected") } tk := measurement.TestKeys.(*stunreachability.TestKeys) - if *tk.Failure != errorx.FailureGenericTimeoutError { + if *tk.Failure != errorsx.FailureGenericTimeoutError { t.Fatal("expected different failure here") } if tk.Endpoint != "stun.l.google.com:19302" { diff --git a/internal/engine/experiment/telegram/telegram.go b/internal/engine/experiment/telegram/telegram.go index 3be82f3..f8a1cbf 100644 --- a/internal/engine/experiment/telegram/telegram.go +++ b/internal/engine/experiment/telegram/telegram.go @@ -11,7 +11,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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" ) const ( @@ -56,7 +56,7 @@ func (tk *TestKeys) Update(v urlgetter.MultiOutput) { tk.TelegramTCPBlocking = false return // found successful access point connection } - if v.TestKeys.FailedOperation == nil || *v.TestKeys.FailedOperation != errorx.ConnectOperation { + if v.TestKeys.FailedOperation == nil || *v.TestKeys.FailedOperation != errorsx.ConnectOperation { tk.TelegramTCPBlocking = false } return diff --git a/internal/engine/experiment/telegram/telegram_test.go b/internal/engine/experiment/telegram/telegram_test.go index 3007534..fd57dbc 100644 --- a/internal/engine/experiment/telegram/telegram_test.go +++ b/internal/engine/experiment/telegram/telegram_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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" ) func TestNewExperimentMeasurer(t *testing.T) { @@ -94,7 +94,7 @@ func TestUpdateWithNoAccessPointsBlocking(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -125,7 +125,7 @@ func TestUpdateWithNilFailedOperation(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -137,7 +137,7 @@ func TestUpdateWithNilFailedOperation(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -159,11 +159,11 @@ func TestUpdateWithNonConnectFailedOperation(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorx.ConnectOperation + s := errorsx.ConnectOperation return &s })(), Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -175,11 +175,11 @@ func TestUpdateWithNonConnectFailedOperation(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorx.HTTPRoundTripOperation + s := errorsx.HTTPRoundTripOperation return &s })(), Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -201,11 +201,11 @@ func TestUpdateWithAllConnectsFailed(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorx.ConnectOperation + s := errorsx.ConnectOperation return &s })(), Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -217,11 +217,11 @@ func TestUpdateWithAllConnectsFailed(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorx.ConnectOperation + s := errorsx.ConnectOperation return &s })(), Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -243,11 +243,11 @@ func TestUpdateWebWithMixedResults(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorx.HTTPRoundTripOperation + s := errorsx.HTTPRoundTripOperation return &s })(), Failure: (func() *string { - s := errorx.FailureEOFError + s := errorsx.FailureEOFError return &s })(), }, @@ -265,7 +265,7 @@ func TestUpdateWebWithMixedResults(t *testing.T) { if tk.TelegramWebStatus != "blocked" { t.Fatal("TelegramWebStatus should be blocked") } - if *tk.TelegramWebFailure != errorx.FailureEOFError { + if *tk.TelegramWebFailure != errorsx.FailureEOFError { t.Fatal("invalid TelegramWebFailure") } } diff --git a/internal/engine/experiment/tor/tor.go b/internal/engine/experiment/tor/tor.go index 7cfd44f..436b7b7 100644 --- a/internal/engine/experiment/tor/tor.go +++ b/internal/engine/experiment/tor/tor.go @@ -18,7 +18,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/legacy/oonidatamodel" "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/runtimex" "github.com/ooni/probe-cli/v3/internal/scrubber" ) @@ -77,7 +77,7 @@ func (tr *TargetResults) fillSummary() { if len(tr.TCPConnect) < 1 { return } - tr.Summary[errorx.ConnectOperation] = Summary{ + tr.Summary[errorsx.ConnectOperation] = Summary{ Failure: tr.TCPConnect[0].Status.Failure, } switch tr.TargetProtocol { diff --git a/internal/engine/experiment/tor/tor_test.go b/internal/engine/experiment/tor/tor_test.go index d9f4645..89c3cff 100644 --- a/internal/engine/experiment/tor/tor_test.go +++ b/internal/engine/experiment/tor/tor_test.go @@ -17,7 +17,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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/scrubber" ) @@ -446,7 +446,7 @@ func TestSummary(t *testing.T) { if len(tr.Summary) != 1 { t.Fatal("cannot find expected entry") } - if *tr.Summary[errorx.ConnectOperation].Failure != failure { + if *tr.Summary[errorsx.ConnectOperation].Failure != failure { t.Fatal("invalid failure") } }) @@ -465,7 +465,7 @@ func TestSummary(t *testing.T) { if len(tr.Summary) != 2 { t.Fatal("cannot find expected entry") } - if tr.Summary[errorx.ConnectOperation].Failure != nil { + if tr.Summary[errorsx.ConnectOperation].Failure != nil { t.Fatal("invalid failure") } if *tr.Summary["handshake"].Failure != failure { @@ -489,7 +489,7 @@ func TestSummary(t *testing.T) { if len(tr.Summary) < 1 { t.Fatal("cannot find expected entry") } - if tr.Summary[errorx.ConnectOperation].Failure != nil { + if tr.Summary[errorsx.ConnectOperation].Failure != nil { t.Fatal("invalid failure") } if handshake == nil { diff --git a/internal/engine/experiment/urlgetter/getter.go b/internal/engine/experiment/urlgetter/getter.go index d1225ec..c85cdd0 100644 --- a/internal/engine/experiment/urlgetter/getter.go +++ b/internal/engine/experiment/urlgetter/getter.go @@ -8,8 +8,8 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" "github.com/ooni/probe-cli/v3/internal/tunnel" ) @@ -54,9 +54,9 @@ func (g Getter) Get(ctx context.Context) (TestKeys, error) { tk, err := g.get(ctx, saver) // Make sure we have an operation in cases where we fail before // hitting our httptransport that does error wrapping. - err = errorx.SafeErrWrapperBuilder{ + err = errorsx.SafeErrWrapperBuilder{ Error: err, - Operation: errorx.TopLevelOperation, + Operation: errorsx.TopLevelOperation, }.MaybeBuild() tk.FailedOperation = archival.NewFailedOperation(err) tk.Failure = archival.NewFailure(err) diff --git a/internal/engine/experiment/urlgetter/getter_integration_test.go b/internal/engine/experiment/urlgetter/getter_integration_test.go index 718c595..c1b5008 100644 --- a/internal/engine/experiment/urlgetter/getter_integration_test.go +++ b/internal/engine/experiment/urlgetter/getter_integration_test.go @@ -10,7 +10,7 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "github.com/ooni/probe-cli/v3/internal/engine/mockable" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestGetterWithVeryShortTimeout(t *testing.T) { @@ -31,7 +31,7 @@ func TestGetterWithVeryShortTimeout(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || *tk.Failure != "generic_timeout_error" { @@ -98,7 +98,7 @@ func TestGetterWithCancelledContextVanilla(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") { @@ -166,7 +166,7 @@ func TestGetterWithCancelledContextAndMethod(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") { @@ -236,7 +236,7 @@ func TestGetterWithCancelledContextNoFollowRedirects(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") { @@ -306,7 +306,7 @@ func TestGetterWithCancelledContextCannotStartTunnel(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || *tk.Failure != "interrupted" { @@ -361,7 +361,7 @@ func TestGetterWithCancelledContextUnknownResolverURL(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || *tk.Failure != "unknown_failure: unsupported resolver scheme" { @@ -446,7 +446,7 @@ func TestGetterIntegrationHTTPS(t *testing.T) { resolveStart = true case "resolve_done": resolveDone = true - case errorx.ConnectOperation: + case errorsx.ConnectOperation: connect = true case "tls_handshake_start": tlsHandshakeStart = true @@ -587,7 +587,7 @@ func TestGetterIntegrationTLSHandshake(t *testing.T) { resolveStart = true case "resolve_done": resolveDone = true - case errorx.ConnectOperation: + case errorsx.ConnectOperation: connect = true case "tls_handshake_start": tlsHandshakeStart = true @@ -705,7 +705,7 @@ func TestGetterHTTPSWithTunnel(t *testing.T) { resolveStart = true case "resolve_done": resolveDone = true - case errorx.ConnectOperation: + case errorsx.ConnectOperation: connect = true case "tls_handshake_start": tlsHandshakeStart = true diff --git a/internal/engine/experiment/urlgetter/runner.go b/internal/engine/experiment/urlgetter/runner.go index da3d92d..be34093 100644 --- a/internal/engine/experiment/urlgetter/runner.go +++ b/internal/engine/experiment/urlgetter/runner.go @@ -11,7 +11,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/httpheader" "github.com/ooni/probe-cli/v3/internal/engine/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" "github.com/ooni/probe-cli/v3/internal/runtimex" ) @@ -19,9 +19,9 @@ import ( const httpRequestFailed = "http_request_failed" // ErrHTTPRequestFailed indicates that the HTTP request failed. -var ErrHTTPRequestFailed = &errorx.ErrWrapper{ +var ErrHTTPRequestFailed = &errorsx.ErrWrapper{ Failure: httpRequestFailed, - Operation: errorx.TopLevelOperation, + Operation: errorsx.TopLevelOperation, WrappedErr: errors.New(httpRequestFailed), } diff --git a/internal/engine/experiment/webconnectivity/control.go b/internal/engine/experiment/webconnectivity/control.go index f3cd6b3..29f0096 100644 --- a/internal/engine/experiment/webconnectivity/control.go +++ b/internal/engine/experiment/webconnectivity/control.go @@ -6,7 +6,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/geolocate" "github.com/ooni/probe-cli/v3/internal/engine/httpx" "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" ) // ControlRequest is the request that we send to the control @@ -59,9 +59,9 @@ func Control( } sess.Logger().Infof("control for %s...", creq.HTTPRequest) // make sure error is wrapped - err = errorx.SafeErrWrapperBuilder{ + err = errorsx.SafeErrWrapperBuilder{ Error: clnt.PostJSON(ctx, "/", creq, &out), - Operation: errorx.TopLevelOperation, + Operation: errorsx.TopLevelOperation, }.MaybeBuild() sess.Logger().Infof("control for %s... %+v", creq.HTTPRequest, err) (&out.DNS).FillASNs(sess) diff --git a/internal/engine/experiment/webconnectivity/dnsanalysis.go b/internal/engine/experiment/webconnectivity/dnsanalysis.go index 5c0bb39..cf103c3 100644 --- a/internal/engine/experiment/webconnectivity/dnsanalysis.go +++ b/internal/engine/experiment/webconnectivity/dnsanalysis.go @@ -4,7 +4,7 @@ import ( "net" "net/url" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) // DNSAnalysisResult contains the results of analysing comparing @@ -44,7 +44,7 @@ func DNSAnalysis(URL *url.URL, measurement DNSLookupResult, switch *control.DNS.Failure { case DNSNameError: // the control returns this on NXDOMAIN error switch *measurement.Failure { - case errorx.FailureDNSNXDOMAINError: + case errorsx.FailureDNSNXDOMAINError: out.DNSConsistency = &DNSConsistent } } diff --git a/internal/engine/experiment/webconnectivity/dnsanalysis_test.go b/internal/engine/experiment/webconnectivity/dnsanalysis_test.go index d4369e9..47502fa 100644 --- a/internal/engine/experiment/webconnectivity/dnsanalysis_test.go +++ b/internal/engine/experiment/webconnectivity/dnsanalysis_test.go @@ -7,11 +7,11 @@ import ( "github.com/google/go-cmp/cmp" "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestDNSAnalysis(t *testing.T) { - measurementFailure := errorx.FailureDNSNXDOMAINError + measurementFailure := errorsx.FailureDNSNXDOMAINError controlFailure := webconnectivity.DNSNameError eofFailure := io.EOF.Error() type args struct { diff --git a/internal/engine/experiment/webconnectivity/summary.go b/internal/engine/experiment/webconnectivity/summary.go index 2a6b0ea..1416d5a 100644 --- a/internal/engine/experiment/webconnectivity/summary.go +++ b/internal/engine/experiment/webconnectivity/summary.go @@ -5,7 +5,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity/internal" "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" ) // The following set of status flags identifies in a more nuanced way the @@ -127,7 +127,7 @@ func Summarize(tk *TestKeys) (out Summary) { // If DNS failed with NXDOMAIN and the control DNS is consistent, then it // means this website does not exist anymore. if tk.DNSExperimentFailure != nil && - *tk.DNSExperimentFailure == errorx.FailureDNSNXDOMAINError && + *tk.DNSExperimentFailure == errorsx.FailureDNSNXDOMAINError && tk.DNSConsistency != nil && *tk.DNSConsistency == DNSConsistent { // TODO(bassosimone): MK flags this as accessible. This result is debatable. We // are doing what MK does. But we most likely want to make it better later. @@ -140,7 +140,7 @@ func Summarize(tk *TestKeys) (out Summary) { // Otherwise, if DNS failed with NXDOMAIN, it's DNS based blocking. // TODO(bassosimone): do we wanna include other errors here? Like timeout? if tk.DNSExperimentFailure != nil && - *tk.DNSExperimentFailure == errorx.FailureDNSNXDOMAINError { + *tk.DNSExperimentFailure == errorsx.FailureDNSNXDOMAINError { out.Accessible = &inaccessible out.BlockingReason = &dns out.Status |= StatusAnomalyDNS | StatusExperimentDNS @@ -184,41 +184,41 @@ func Summarize(tk *TestKeys) (out Summary) { if tk.Requests[0].Failure != nil { out.Status |= StatusExperimentHTTP switch *tk.Requests[0].Failure { - case errorx.FailureConnectionRefused: + case errorsx.FailureConnectionRefused: // This is possibly because a subsequent connection to some // other endpoint has been blocked. We call this http-failure // because this is what MK would actually do. out.BlockingReason = &httpFailure out.Accessible = &inaccessible out.Status |= StatusAnomalyConnect - case errorx.FailureConnectionReset: + case errorsx.FailureConnectionReset: // We don't currently support TLS failures and we don't have a // way to know if it was during TLS or later. So, for now we are // going to call this error condition an http-failure. out.BlockingReason = &httpFailure out.Accessible = &inaccessible out.Status |= StatusAnomalyReadWrite - case errorx.FailureDNSNXDOMAINError: + case errorsx.FailureDNSNXDOMAINError: // This is possibly because a subsequent resolution to // some other domain name has been blocked. out.BlockingReason = &dns out.Accessible = &inaccessible out.Status |= StatusAnomalyDNS - case errorx.FailureEOFError: + case errorsx.FailureEOFError: // We have seen this happening with TLS handshakes as well as // sometimes with HTTP blocking. So http-failure. out.BlockingReason = &httpFailure out.Accessible = &inaccessible out.Status |= StatusAnomalyReadWrite - case errorx.FailureGenericTimeoutError: + case errorsx.FailureGenericTimeoutError: // Alas, here we don't know whether it's connect or whether it's // perhaps the TLS handshake. So use the same classification used by MK. out.BlockingReason = &httpFailure out.Accessible = &inaccessible out.Status |= StatusAnomalyUnknown - case errorx.FailureSSLInvalidHostname, - errorx.FailureSSLInvalidCertificate, - errorx.FailureSSLUnknownAuthority: + case errorsx.FailureSSLInvalidHostname, + errorsx.FailureSSLInvalidCertificate, + errorsx.FailureSSLUnknownAuthority: // We treat these three cases equally. Misconfiguration is a bit // less likely since we also checked with the control. Since there // is no TLS, for now we're going to call this http-failure. diff --git a/internal/engine/experiment/webconnectivity/summary_test.go b/internal/engine/experiment/webconnectivity/summary_test.go index e728169..2488d2b 100644 --- a/internal/engine/experiment/webconnectivity/summary_test.go +++ b/internal/engine/experiment/webconnectivity/summary_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestSummarize(t *testing.T) { @@ -18,14 +18,14 @@ func TestSummarize(t *testing.T) { httpDiff = "http-diff" httpFailure = "http-failure" nilstring *string - probeConnectionRefused = errorx.FailureConnectionRefused - probeConnectionReset = errorx.FailureConnectionReset - probeEOFError = errorx.FailureEOFError - probeNXDOMAIN = errorx.FailureDNSNXDOMAINError - probeTimeout = errorx.FailureGenericTimeoutError - probeSSLInvalidHost = errorx.FailureSSLInvalidHostname - probeSSLInvalidCert = errorx.FailureSSLInvalidCertificate - probeSSLUnknownAuth = errorx.FailureSSLUnknownAuthority + probeConnectionRefused = errorsx.FailureConnectionRefused + probeConnectionReset = errorsx.FailureConnectionReset + probeEOFError = errorsx.FailureEOFError + probeNXDOMAIN = errorsx.FailureDNSNXDOMAINError + probeTimeout = errorsx.FailureGenericTimeoutError + probeSSLInvalidHost = errorsx.FailureSSLInvalidHostname + probeSSLInvalidCert = errorsx.FailureSSLInvalidCertificate + probeSSLUnknownAuth = errorsx.FailureSSLUnknownAuthority tcpIP = "tcp_ip" trueValue = true ) diff --git a/internal/engine/experiment/webconnectivity/webconnectivity_test.go b/internal/engine/experiment/webconnectivity/webconnectivity_test.go index dc4dc35..8dd2abb 100644 --- a/internal/engine/experiment/webconnectivity/webconnectivity_test.go +++ b/internal/engine/experiment/webconnectivity/webconnectivity_test.go @@ -13,7 +13,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestNewExperimentMeasurer(t *testing.T) { @@ -69,10 +69,10 @@ func TestMeasureWithCancelledContext(t *testing.T) { t.Fatal(err) } tk := measurement.TestKeys.(*webconnectivity.TestKeys) - if *tk.ControlFailure != errorx.FailureInterrupted { + if *tk.ControlFailure != errorsx.FailureInterrupted { t.Fatal("unexpected control_failure") } - if *tk.DNSExperimentFailure != errorx.FailureInterrupted { + if *tk.DNSExperimentFailure != errorsx.FailureInterrupted { t.Fatal("unexpected dns_experiment_failure") } if tk.HTTPExperimentFailure != nil { diff --git a/internal/engine/legacy/netx/http.go b/internal/engine/legacy/netx/http.go index d4063f0..c62c483 100644 --- a/internal/engine/legacy/netx/http.go +++ b/internal/engine/legacy/netx/http.go @@ -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 } diff --git a/internal/engine/legacy/netx/http_test.go b/internal/engine/legacy/netx/http_test.go index 52794ca..9b163db 100644 --- a/internal/engine/legacy/netx/http_test.go +++ b/internal/engine/legacy/netx/http_test.go @@ -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 { diff --git a/internal/engine/legacy/netx/modelx/modelx_test.go b/internal/engine/legacy/netx/modelx/modelx_test.go index a0ec4b4..191bbc3 100644 --- a/internal/engine/legacy/netx/modelx/modelx_test.go +++ b/internal/engine/legacy/netx/modelx/modelx_test.go @@ -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, } diff --git a/internal/engine/legacy/netx/oldhttptransport/tracetripper.go b/internal/engine/legacy/netx/oldhttptransport/tracetripper.go index 87c8313..a8fe33c 100644 --- a/internal/engine/legacy/netx/oldhttptransport/tracetripper.go +++ b/internal/engine/legacy/netx/oldhttptransport/tracetripper.go @@ -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() diff --git a/internal/engine/legacy/oonidatamodel/oonidatamodel.go b/internal/engine/legacy/oonidatamodel/oonidatamodel.go index fc6e96e..da6ac9b 100644 --- a/internal/engine/legacy/oonidatamodel/oonidatamodel.go +++ b/internal/engine/legacy/oonidatamodel/oonidatamodel.go @@ -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(), }) diff --git a/internal/engine/legacy/oonidatamodel/oonidatamodel_test.go b/internal/engine/legacy/oonidatamodel/oonidatamodel_test.go index 0435d17..a6c0eae 100644 --- a/internal/engine/legacy/oonidatamodel/oonidatamodel_test.go +++ b/internal/engine/legacy/oonidatamodel/oonidatamodel_test.go @@ -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) { diff --git a/internal/engine/legacy/oonitemplates/oonitemplates_test.go b/internal/engine/legacy/oonitemplates/oonitemplates_test.go index 98b6136..ba3287a 100644 --- a/internal/engine/legacy/oonitemplates/oonitemplates_test.go +++ b/internal/engine/legacy/oonitemplates/oonitemplates_test.go @@ -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") } } diff --git a/internal/engine/netx/archival/archival.go b/internal/engine/netx/archival/archival.go index b50a8d0..1d51f9b 100644 --- a/internal/engine/netx/archival/archival.go +++ b/internal/engine/netx/archival/archival.go @@ -18,8 +18,8 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/geolocate" "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/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) // ExtSpec describes a data format extension @@ -80,7 +80,7 @@ type TCPConnectEntry struct { func NewTCPConnectList(begin time.Time, events []trace.Event) []TCPConnectEntry { var out []TCPConnectEntry for _, event := range events { - if event.Name != errorx.ConnectOperation { + if event.Name != errorsx.ConnectOperation { continue } if event.Proto != "tcp" { @@ -110,11 +110,11 @@ func NewFailure(err error) *string { // The following code guarantees that the error is always wrapped even // when we could not actually hit our code that does the wrapping. A case // in which this happen is with context deadline for HTTP. - err = errorx.SafeErrWrapperBuilder{ + err = errorsx.SafeErrWrapperBuilder{ Error: err, - Operation: errorx.TopLevelOperation, + Operation: errorsx.TopLevelOperation, }.MaybeBuild() - errWrapper := err.(*errorx.ErrWrapper) + errWrapper := err.(*errorsx.ErrWrapper) s := errWrapper.Failure if s == "" { s = "unknown_failure: errWrapper.Failure is empty" @@ -128,8 +128,8 @@ func NewFailedOperation(err error) *string { return nil } var ( - errWrapper *errorx.ErrWrapper - s = errorx.UnknownOperation + errWrapper *errorsx.ErrWrapper + s = errorsx.UnknownOperation ) if errors.As(err, &errWrapper) && errWrapper.Operation != "" { s = errWrapper.Operation @@ -474,7 +474,7 @@ type NetworkEvent struct { func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent { var out []NetworkEvent for _, ev := range events { - if ev.Name == errorx.ConnectOperation { + if ev.Name == errorsx.ConnectOperation { out = append(out, NetworkEvent{ Address: ev.Address, Failure: NewFailure(ev.Err), @@ -484,7 +484,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent }) continue } - if ev.Name == errorx.ReadOperation { + if ev.Name == errorsx.ReadOperation { out = append(out, NetworkEvent{ Failure: NewFailure(ev.Err), Operation: ev.Name, @@ -493,7 +493,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent }) continue } - if ev.Name == errorx.WriteOperation { + if ev.Name == errorsx.WriteOperation { out = append(out, NetworkEvent{ Failure: NewFailure(ev.Err), Operation: ev.Name, @@ -502,7 +502,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent }) continue } - if ev.Name == errorx.ReadFromOperation { + if ev.Name == errorsx.ReadFromOperation { out = append(out, NetworkEvent{ Address: ev.Address, Failure: NewFailure(ev.Err), @@ -512,7 +512,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent }) continue } - if ev.Name == errorx.WriteToOperation { + if ev.Name == errorsx.WriteToOperation { out = append(out, NetworkEvent{ Address: ev.Address, Failure: NewFailure(ev.Err), diff --git a/internal/engine/netx/archival/archival_test.go b/internal/engine/netx/archival/archival_test.go index 7fdc471..a9569ef 100644 --- a/internal/engine/netx/archival/archival_test.go +++ b/internal/engine/netx/archival/archival_test.go @@ -14,8 +14,8 @@ import ( "github.com/gorilla/websocket" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestNewTCPConnectList(t *testing.T) { @@ -47,20 +47,20 @@ func TestNewTCPConnectList(t *testing.T) { }, { Address: "8.8.8.8:853", Duration: 30 * time.Millisecond, - Name: errorx.ConnectOperation, + Name: errorsx.ConnectOperation, Proto: "tcp", Time: begin.Add(130 * time.Millisecond), }, { Address: "8.8.8.8:853", Duration: 55 * time.Millisecond, - Name: errorx.ConnectOperation, + Name: errorsx.ConnectOperation, Proto: "udp", Time: begin.Add(130 * time.Millisecond), }, { Address: "8.8.4.4:53", Duration: 50 * time.Millisecond, Err: io.EOF, - Name: errorx.ConnectOperation, + Name: errorsx.ConnectOperation, Proto: "tcp", Time: begin.Add(180 * time.Millisecond), }}, @@ -314,14 +314,14 @@ func TestNewDNSQueriesList(t *testing.T) { }, { Address: "8.8.8.8:853", Duration: 30 * time.Millisecond, - Name: errorx.ConnectOperation, + Name: errorsx.ConnectOperation, Proto: "tcp", Time: begin.Add(130 * time.Millisecond), }, { Address: "8.8.4.4:53", Duration: 50 * time.Millisecond, Err: io.EOF, - Name: errorx.ConnectOperation, + Name: errorsx.ConnectOperation, Proto: "tcp", Time: begin.Add(180 * time.Millisecond), }}, @@ -371,7 +371,7 @@ func TestNewDNSQueriesList(t *testing.T) { args: args{ begin: begin, events: []trace.Event{{ - Err: &errorx.ErrWrapper{Failure: errorx.FailureDNSNXDOMAINError}, + Err: &errorsx.ErrWrapper{Failure: errorsx.FailureDNSNXDOMAINError}, Hostname: "dns.google.com", Name: "resolve_done", Time: begin.Add(200 * time.Millisecond), @@ -380,14 +380,14 @@ func TestNewDNSQueriesList(t *testing.T) { want: []archival.DNSQueryEntry{{ Answers: nil, Failure: archival.NewFailure( - &errorx.ErrWrapper{Failure: errorx.FailureDNSNXDOMAINError}), + &errorsx.ErrWrapper{Failure: errorsx.FailureDNSNXDOMAINError}), Hostname: "dns.google.com", QueryType: "A", T: 0.2, }, { Answers: nil, Failure: archival.NewFailure( - &errorx.ErrWrapper{Failure: errorx.FailureDNSNXDOMAINError}), + &errorsx.ErrWrapper{Failure: errorsx.FailureDNSNXDOMAINError}), Hostname: "dns.google.com", QueryType: "AAAA", T: 0.2, @@ -425,35 +425,35 @@ func TestNewNetworkEventsList(t *testing.T) { args: args{ begin: begin, events: []trace.Event{{ - Name: errorx.ConnectOperation, + Name: errorsx.ConnectOperation, Address: "8.8.8.8:853", Err: io.EOF, Proto: "tcp", Time: begin.Add(7 * time.Millisecond), }, { - Name: errorx.ReadOperation, + Name: errorsx.ReadOperation, Err: context.Canceled, NumBytes: 7117, Time: begin.Add(11 * time.Millisecond), }, { Address: "8.8.8.8:853", - Name: errorx.ReadFromOperation, + Name: errorsx.ReadFromOperation, Err: context.Canceled, NumBytes: 7117, Time: begin.Add(11 * time.Millisecond), }, { - Name: errorx.WriteOperation, + Name: errorsx.WriteOperation, Err: websocket.ErrBadHandshake, NumBytes: 4114, Time: begin.Add(14 * time.Millisecond), }, { Address: "8.8.8.8:853", - Name: errorx.WriteToOperation, + Name: errorsx.WriteToOperation, Err: websocket.ErrBadHandshake, NumBytes: 4114, Time: begin.Add(14 * time.Millisecond), }, { - Name: errorx.CloseOperation, + Name: errorsx.CloseOperation, Err: websocket.ErrReadLimit, Time: begin.Add(17 * time.Millisecond), }}, @@ -461,34 +461,34 @@ func TestNewNetworkEventsList(t *testing.T) { want: []archival.NetworkEvent{{ Address: "8.8.8.8:853", Failure: archival.NewFailure(io.EOF), - Operation: errorx.ConnectOperation, + Operation: errorsx.ConnectOperation, Proto: "tcp", T: 0.007, }, { Failure: archival.NewFailure(context.Canceled), NumBytes: 7117, - Operation: errorx.ReadOperation, + Operation: errorsx.ReadOperation, T: 0.011, }, { Address: "8.8.8.8:853", Failure: archival.NewFailure(context.Canceled), NumBytes: 7117, - Operation: errorx.ReadFromOperation, + Operation: errorsx.ReadFromOperation, T: 0.011, }, { Failure: archival.NewFailure(websocket.ErrBadHandshake), NumBytes: 4114, - Operation: errorx.WriteOperation, + Operation: errorsx.WriteOperation, T: 0.014, }, { Address: "8.8.8.8:853", Failure: archival.NewFailure(websocket.ErrBadHandshake), NumBytes: 4114, - Operation: errorx.WriteToOperation, + Operation: errorsx.WriteToOperation, T: 0.014, }, { Failure: archival.NewFailure(websocket.ErrReadLimit), - Operation: errorx.CloseOperation, + Operation: errorsx.CloseOperation, T: 0.017, }}, }} @@ -523,7 +523,7 @@ func TestNewTLSHandshakesList(t *testing.T) { args: args{ begin: begin, events: []trace.Event{{ - Name: errorx.CloseOperation, + Name: errorsx.CloseOperation, Err: websocket.ErrReadLimit, Time: begin.Add(17 * time.Millisecond), }, { @@ -929,18 +929,18 @@ func TestNewFailure(t *testing.T) { }, { name: "when error is wrapped and failure meaningful", args: args{ - err: &errorx.ErrWrapper{ - Failure: errorx.FailureConnectionRefused, + err: &errorsx.ErrWrapper{ + Failure: errorsx.FailureConnectionRefused, }, }, want: func() *string { - s := errorx.FailureConnectionRefused + s := errorsx.FailureConnectionRefused return &s }(), }, { name: "when error is wrapped and failure is not meaningful", args: args{ - err: &errorx.ErrWrapper{}, + err: &errorsx.ErrWrapper{}, }, want: func() *string { s := "unknown_failure: errWrapper.Failure is empty" @@ -1002,24 +1002,24 @@ func TestNewFailedOperation(t *testing.T) { }, { name: "With wrapped error and non-empty operation", args: args{ - err: &errorx.ErrWrapper{ - Failure: errorx.FailureConnectionRefused, - Operation: errorx.ConnectOperation, + err: &errorsx.ErrWrapper{ + Failure: errorsx.FailureConnectionRefused, + Operation: errorsx.ConnectOperation, }, }, want: (func() *string { - s := errorx.ConnectOperation + s := errorsx.ConnectOperation return &s })(), }, { name: "With wrapped error and empty operation", args: args{ - err: &errorx.ErrWrapper{ - Failure: errorx.FailureConnectionRefused, + err: &errorsx.ErrWrapper{ + Failure: errorsx.FailureConnectionRefused, }, }, want: (func() *string { - s := errorx.UnknownOperation + s := errorsx.UnknownOperation return &s })(), }, { @@ -1028,7 +1028,7 @@ func TestNewFailedOperation(t *testing.T) { err: io.EOF, }, want: (func() *string { - s := errorx.UnknownOperation + s := errorsx.UnknownOperation return &s })(), }} diff --git a/internal/engine/netx/dialer/errorwrapper.go b/internal/engine/netx/dialer/errorwrapper.go index 0d11cde..ed39f6a 100644 --- a/internal/engine/netx/dialer/errorwrapper.go +++ b/internal/engine/netx/dialer/errorwrapper.go @@ -4,7 +4,7 @@ import ( "context" "net" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) // errorWrapperDialer is a dialer that performs err wrapping @@ -15,9 +15,9 @@ type errorWrapperDialer struct { // DialContext implements Dialer.DialContext func (d *errorWrapperDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) { conn, err := d.Dialer.DialContext(ctx, network, address) - err = errorx.SafeErrWrapperBuilder{ + err = errorsx.SafeErrWrapperBuilder{ Error: err, - Operation: errorx.ConnectOperation, + Operation: errorsx.ConnectOperation, }.MaybeBuild() if err != nil { return nil, err @@ -33,9 +33,9 @@ type errorWrapperConn struct { // Read implements net.Conn.Read func (c *errorWrapperConn) Read(b []byte) (n int, err error) { n, err = c.Conn.Read(b) - err = errorx.SafeErrWrapperBuilder{ + err = errorsx.SafeErrWrapperBuilder{ Error: err, - Operation: errorx.ReadOperation, + Operation: errorsx.ReadOperation, }.MaybeBuild() return } @@ -43,9 +43,9 @@ func (c *errorWrapperConn) Read(b []byte) (n int, err error) { // Write implements net.Conn.Write func (c *errorWrapperConn) Write(b []byte) (n int, err error) { n, err = c.Conn.Write(b) - err = errorx.SafeErrWrapperBuilder{ + err = errorsx.SafeErrWrapperBuilder{ Error: err, - Operation: errorx.WriteOperation, + Operation: errorsx.WriteOperation, }.MaybeBuild() return } @@ -53,9 +53,9 @@ func (c *errorWrapperConn) Write(b []byte) (n int, err error) { // Close implements net.Conn.Close func (c *errorWrapperConn) Close() (err error) { err = c.Conn.Close() - err = errorx.SafeErrWrapperBuilder{ + err = errorsx.SafeErrWrapperBuilder{ Error: err, - Operation: errorx.CloseOperation, + Operation: errorsx.CloseOperation, }.MaybeBuild() return } diff --git a/internal/engine/netx/dialer/errorwrapper_test.go b/internal/engine/netx/dialer/errorwrapper_test.go index 122afcd..bda7223 100644 --- a/internal/engine/netx/dialer/errorwrapper_test.go +++ b/internal/engine/netx/dialer/errorwrapper_test.go @@ -7,7 +7,7 @@ import ( "net" "testing" - "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/netxmocks" ) @@ -22,21 +22,21 @@ func TestErrorWrapperFailure(t *testing.T) { if conn != nil { t.Fatal("expected a nil conn here") } - errorWrapperCheckErr(t, err, errorx.ConnectOperation) + errorWrapperCheckErr(t, err, errorsx.ConnectOperation) } func errorWrapperCheckErr(t *testing.T, err error, op string) { if !errors.Is(err, io.EOF) { t.Fatal("expected another error here") } - var errWrapper *errorx.ErrWrapper + var errWrapper *errorsx.ErrWrapper if !errors.As(err, &errWrapper) { t.Fatal("cannot cast to ErrWrapper") } if errWrapper.Operation != op { t.Fatal("unexpected Operation") } - if errWrapper.Failure != errorx.FailureEOFError { + if errWrapper.Failure != errorsx.FailureEOFError { t.Fatal("unexpected failure") } } @@ -69,11 +69,11 @@ func TestErrorWrapperSuccess(t *testing.T) { t.Fatal("expected non-nil conn here") } count, err := conn.Read(nil) - errorWrapperCheckIOResult(t, count, err, errorx.ReadOperation) + errorWrapperCheckIOResult(t, count, err, errorsx.ReadOperation) count, err = conn.Write(nil) - errorWrapperCheckIOResult(t, count, err, errorx.WriteOperation) + errorWrapperCheckIOResult(t, count, err, errorsx.WriteOperation) err = conn.Close() - errorWrapperCheckErr(t, err, errorx.CloseOperation) + errorWrapperCheckErr(t, err, errorsx.CloseOperation) } func errorWrapperCheckIOResult(t *testing.T, count int, err error, op string) { diff --git a/internal/engine/netx/dialer/saver.go b/internal/engine/netx/dialer/saver.go index 682fab2..75c9d25 100644 --- a/internal/engine/netx/dialer/saver.go +++ b/internal/engine/netx/dialer/saver.go @@ -5,8 +5,8 @@ import ( "net" "time" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) // saverDialer saves events occurring during the dial @@ -24,7 +24,7 @@ func (d *saverDialer) DialContext(ctx context.Context, network, address string) Address: address, Duration: stop.Sub(start), Err: err, - Name: errorx.ConnectOperation, + Name: errorsx.ConnectOperation, Proto: network, Time: stop, }) @@ -61,7 +61,7 @@ func (c *saverConn) Read(p []byte) (int, error) { Duration: stop.Sub(start), Err: err, NumBytes: count, - Name: errorx.ReadOperation, + Name: errorsx.ReadOperation, Time: stop, }) return count, err @@ -76,7 +76,7 @@ func (c *saverConn) Write(p []byte) (int, error) { Duration: stop.Sub(start), Err: err, NumBytes: count, - Name: errorx.WriteOperation, + Name: errorsx.WriteOperation, Time: stop, }) return count, err diff --git a/internal/engine/netx/dialer/saver_test.go b/internal/engine/netx/dialer/saver_test.go index ce962f1..86d0853 100644 --- a/internal/engine/netx/dialer/saver_test.go +++ b/internal/engine/netx/dialer/saver_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" "github.com/ooni/probe-cli/v3/internal/netxmocks" ) @@ -44,7 +44,7 @@ func TestSaverDialerFailure(t *testing.T) { if !errors.Is(ev[0].Err, expected) { t.Fatal("unexpected Err") } - if ev[0].Name != errorx.ConnectOperation { + if ev[0].Name != errorsx.ConnectOperation { t.Fatal("unexpected Name") } if ev[0].Proto != "tcp" { diff --git a/internal/engine/netx/integration_test.go b/internal/engine/netx/integration_test.go index 73fffff..37e2002 100644 --- a/internal/engine/netx/integration_test.go +++ b/internal/engine/netx/integration_test.go @@ -9,8 +9,8 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/bytecounter" "github.com/ooni/probe-cli/v3/internal/engine/netx" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" "github.com/ooni/probe-cli/v3/internal/iox" ) @@ -78,10 +78,10 @@ func TestBogonResolutionNotBroken(t *testing.T) { Logger: log.Log, }) addrs, err := r.LookupHost(context.Background(), "www.google.com") - if !errors.Is(err, errorx.ErrDNSBogon) { + if !errors.Is(err, errorsx.ErrDNSBogon) { t.Fatal("not the error we expected") } - if err.Error() != errorx.FailureDNSBogonError { + if err.Error() != errorsx.FailureDNSBogonError { t.Fatal("error not correctly wrapped") } if len(addrs) > 0 { diff --git a/internal/engine/netx/quicdialer/errorwrapper.go b/internal/engine/netx/quicdialer/errorwrapper.go index 0c69e4a..a3e82e9 100644 --- a/internal/engine/netx/quicdialer/errorwrapper.go +++ b/internal/engine/netx/quicdialer/errorwrapper.go @@ -5,7 +5,7 @@ import ( "crypto/tls" "github.com/lucas-clemente/quic-go" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) // ErrorWrapperDialer is a dialer that performs quic err wrapping @@ -18,10 +18,10 @@ func (d ErrorWrapperDialer) DialContext( ctx context.Context, network string, host string, tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlySession, error) { sess, err := d.Dialer.DialContext(ctx, network, host, tlsCfg, cfg) - err = errorx.SafeErrWrapperBuilder{ - Classifier: errorx.ClassifyQUICFailure, + err = errorsx.SafeErrWrapperBuilder{ + Classifier: errorsx.ClassifyQUICFailure, Error: err, - Operation: errorx.QUICHandshakeOperation, + Operation: errorsx.QUICHandshakeOperation, }.MaybeBuild() if err != nil { return nil, err diff --git a/internal/engine/netx/quicdialer/errorwrapper_test.go b/internal/engine/netx/quicdialer/errorwrapper_test.go index 21896b8..77259e2 100644 --- a/internal/engine/netx/quicdialer/errorwrapper_test.go +++ b/internal/engine/netx/quicdialer/errorwrapper_test.go @@ -8,8 +8,8 @@ import ( "testing" "github.com/lucas-clemente/quic-go" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer" + "github.com/ooni/probe-cli/v3/internal/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite" ) @@ -22,21 +22,21 @@ func TestErrorWrapperFailure(t *testing.T) { if sess != nil { t.Fatal("expected a nil sess here") } - errorWrapperCheckErr(t, err, errorx.QUICHandshakeOperation) + errorWrapperCheckErr(t, err, errorsx.QUICHandshakeOperation) } func errorWrapperCheckErr(t *testing.T, err error, op string) { if !errors.Is(err, io.EOF) { t.Fatal("expected another error here") } - var errWrapper *errorx.ErrWrapper + var errWrapper *errorsx.ErrWrapper if !errors.As(err, &errWrapper) { t.Fatal("cannot cast to ErrWrapper") } if errWrapper.Operation != op { t.Fatal("unexpected Operation") } - if errWrapper.Failure != errorx.FailureEOFError { + if errWrapper.Failure != errorsx.FailureEOFError { t.Fatal("unexpected failure") } } @@ -61,7 +61,7 @@ func TestErrorWrapperInvalidCertificate(t *testing.T) { if sess != nil { t.Fatal("expected nil sess here") } - if err.Error() != errorx.FailureSSLInvalidCertificate { + if err.Error() != errorsx.FailureSSLInvalidCertificate { t.Fatal("unexpected failure") } } diff --git a/internal/engine/netx/quicdialer/system.go b/internal/engine/netx/quicdialer/system.go index 3507460..fbb39f4 100644 --- a/internal/engine/netx/quicdialer/system.go +++ b/internal/engine/netx/quicdialer/system.go @@ -5,8 +5,8 @@ import ( "net" "time" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) // QUICListener listens for QUIC connections. @@ -53,7 +53,7 @@ func (c saverUDPConn) WriteTo(p []byte, addr net.Addr) (int, error) { Duration: stop.Sub(start), Err: err, NumBytes: count, - Name: errorx.WriteToOperation, + Name: errorsx.WriteToOperation, Time: stop, }) return count, err @@ -73,7 +73,7 @@ func (c saverUDPConn) ReadMsgUDP(b, oob []byte) (int, int, int, *net.UDPAddr, er Duration: stop.Sub(start), Err: err, NumBytes: n, - Name: errorx.ReadFromOperation, + Name: errorsx.ReadFromOperation, Time: stop, }) return n, oobn, flags, addr, err diff --git a/internal/engine/netx/quicdialer/system_test.go b/internal/engine/netx/quicdialer/system_test.go index 1ea2440..b7a1d61 100644 --- a/internal/engine/netx/quicdialer/system_test.go +++ b/internal/engine/netx/quicdialer/system_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/lucas-clemente/quic-go" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite" ) @@ -49,7 +49,7 @@ func TestSystemDialerSuccessWithReadWrite(t *testing.T) { t.Fatal("unexpected NumBytes") } switch ev[idx].Name { - case errorx.ReadFromOperation, errorx.WriteToOperation: + case errorsx.ReadFromOperation, errorsx.WriteToOperation: default: t.Fatal("unexpected Name") } diff --git a/internal/engine/netx/resolver/bogon.go b/internal/engine/netx/resolver/bogon.go index 2ba0591..aab1667 100644 --- a/internal/engine/netx/resolver/bogon.go +++ b/internal/engine/netx/resolver/bogon.go @@ -4,7 +4,7 @@ import ( "context" "net" - "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/runtimex" ) @@ -65,7 +65,7 @@ func (r BogonResolver) LookupHost(ctx context.Context, hostname string) ([]strin addrs, err := r.Resolver.LookupHost(ctx, hostname) for _, addr := range addrs { if IsBogon(addr) { - return nil, errorx.ErrDNSBogon + return nil, errorsx.ErrDNSBogon } } return addrs, err diff --git a/internal/engine/netx/resolver/bogon_test.go b/internal/engine/netx/resolver/bogon_test.go index b12f67d..0587009 100644 --- a/internal/engine/netx/resolver/bogon_test.go +++ b/internal/engine/netx/resolver/bogon_test.go @@ -5,8 +5,8 @@ import ( "errors" "testing" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/resolver" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestResolverIsBogon(t *testing.T) { @@ -29,7 +29,7 @@ func TestBogonAwareResolverWithBogon(t *testing.T) { Resolver: resolver.NewFakeResolverWithResult([]string{"127.0.0.1"}), } addrs, err := r.LookupHost(context.Background(), "dns.google.com") - if !errors.Is(err, errorx.ErrDNSBogon) { + if !errors.Is(err, errorsx.ErrDNSBogon) { t.Fatal("not the error we expected") } if len(addrs) > 0 { diff --git a/internal/engine/netx/resolver/errorwrapper.go b/internal/engine/netx/resolver/errorwrapper.go index 813c473..9a34cc5 100644 --- a/internal/engine/netx/resolver/errorwrapper.go +++ b/internal/engine/netx/resolver/errorwrapper.go @@ -3,7 +3,7 @@ package resolver import ( "context" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) // ErrorWrapperResolver is a Resolver that knows about wrapping errors. @@ -14,10 +14,10 @@ type ErrorWrapperResolver struct { // LookupHost implements Resolver.LookupHost func (r ErrorWrapperResolver) LookupHost(ctx context.Context, hostname string) ([]string, error) { addrs, err := r.Resolver.LookupHost(ctx, hostname) - err = errorx.SafeErrWrapperBuilder{ - Classifier: errorx.ClassifyResolveFailure, + err = errorsx.SafeErrWrapperBuilder{ + Classifier: errorsx.ClassifyResolveFailure, Error: err, - Operation: errorx.ResolveOperation, + Operation: errorsx.ResolveOperation, }.MaybeBuild() return addrs, err } diff --git a/internal/engine/netx/resolver/errorwrapper_test.go b/internal/engine/netx/resolver/errorwrapper_test.go index f30692c..7b900d3 100644 --- a/internal/engine/netx/resolver/errorwrapper_test.go +++ b/internal/engine/netx/resolver/errorwrapper_test.go @@ -5,8 +5,8 @@ import ( "errors" "testing" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/resolver" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestErrorWrapperSuccess(t *testing.T) { @@ -32,14 +32,14 @@ func TestErrorWrapperFailure(t *testing.T) { if addrs != nil { t.Fatal("expected nil addr here") } - var errWrapper *errorx.ErrWrapper + var errWrapper *errorsx.ErrWrapper if !errors.As(err, &errWrapper) { t.Fatal("cannot properly cast the returned error") } - if errWrapper.Failure != errorx.FailureDNSNXDOMAINError { + if errWrapper.Failure != errorsx.FailureDNSNXDOMAINError { t.Fatal("unexpected failure") } - if errWrapper.Operation != errorx.ResolveOperation { + if errWrapper.Operation != errorsx.ResolveOperation { t.Fatal("unexpected Operation") } } diff --git a/internal/engine/netx/tlsdialer/saver_test.go b/internal/engine/netx/tlsdialer/saver_test.go index 5aeb820..83d153c 100644 --- a/internal/engine/netx/tlsdialer/saver_test.go +++ b/internal/engine/netx/tlsdialer/saver_test.go @@ -9,9 +9,9 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/engine/netx/dialer" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/tlsdialer" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite" ) @@ -69,7 +69,7 @@ func TestSaverTLSHandshakerSuccessWithReadWrite(t *testing.T) { t.Fatal("unexpected NumBytes") } switch ev[idx].Name { - case errorx.ReadOperation, errorx.WriteOperation: + case errorsx.ReadOperation, errorsx.WriteOperation: default: t.Fatal("unexpected Name") } diff --git a/internal/engine/netx/tlsdialer/tls.go b/internal/engine/netx/tlsdialer/tls.go index d98f763..8a5384f 100644 --- a/internal/engine/netx/tlsdialer/tls.go +++ b/internal/engine/netx/tlsdialer/tls.go @@ -8,7 +8,7 @@ import ( "time" "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" ) // UnderlyingDialer is the underlying dialer type. @@ -32,10 +32,10 @@ func (h ErrorWrapperTLSHandshaker) Handshake( ctx context.Context, conn net.Conn, config *tls.Config, ) (net.Conn, tls.ConnectionState, error) { tlsconn, state, err := h.TLSHandshaker.Handshake(ctx, conn, config) - err = errorx.SafeErrWrapperBuilder{ - Classifier: errorx.ClassifyTLSFailure, + err = errorsx.SafeErrWrapperBuilder{ + Classifier: errorsx.ClassifyTLSFailure, Error: err, - Operation: errorx.TLSHandshakeOperation, + Operation: errorsx.TLSHandshakeOperation, }.MaybeBuild() return tlsconn, state, err } diff --git a/internal/engine/netx/tlsdialer/tls_test.go b/internal/engine/netx/tlsdialer/tls_test.go index 64161bc..e2a2011 100644 --- a/internal/engine/netx/tlsdialer/tls_test.go +++ b/internal/engine/netx/tlsdialer/tls_test.go @@ -10,8 +10,8 @@ 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/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/tlsdialer" + "github.com/ooni/probe-cli/v3/internal/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite" ) @@ -48,14 +48,14 @@ func TestErrorWrapperTLSHandshakerFailure(t *testing.T) { if conn != nil { t.Fatal("expected nil con here") } - var errWrapper *errorx.ErrWrapper + var errWrapper *errorsx.ErrWrapper if !errors.As(err, &errWrapper) { t.Fatal("cannot cast to ErrWrapper") } - if errWrapper.Failure != errorx.FailureEOFError { + if errWrapper.Failure != errorsx.FailureEOFError { t.Fatal("unexpected Failure") } - if errWrapper.Operation != errorx.TLSHandshakeOperation { + if errWrapper.Operation != errorsx.TLSHandshakeOperation { t.Fatal("unexpected Operation") } } diff --git a/internal/engine/netx/errorx/errno_unix.go b/internal/errorsx/errno_unix.go similarity index 98% rename from internal/engine/netx/errorx/errno_unix.go rename to internal/errorsx/errno_unix.go index 57491b7..82e6ede 100644 --- a/internal/engine/netx/errorx/errno_unix.go +++ b/internal/errorsx/errno_unix.go @@ -1,4 +1,4 @@ -package errorx +package errorsx import "golang.org/x/sys/unix" diff --git a/internal/engine/netx/errorx/errno_windows.go b/internal/errorsx/errno_windows.go similarity index 98% rename from internal/engine/netx/errorx/errno_windows.go rename to internal/errorsx/errno_windows.go index dbe6826..730efc6 100644 --- a/internal/engine/netx/errorx/errno_windows.go +++ b/internal/errorsx/errno_windows.go @@ -1,4 +1,4 @@ -package errorx +package errorsx import "golang.org/x/sys/windows" diff --git a/internal/engine/netx/errorx/errorx.go b/internal/errorsx/errorsx.go similarity index 99% rename from internal/engine/netx/errorx/errorx.go rename to internal/errorsx/errorsx.go index f71cc92..7d82a6c 100644 --- a/internal/engine/netx/errorx/errorx.go +++ b/internal/errorsx/errorsx.go @@ -1,5 +1,5 @@ -// Package errorx contains error extensions -package errorx +// Package errorsx contains error extensions. +package errorsx // TODO: eventually we want to re-structure the error classification code by clearly separating the layers where the error occur: // diff --git a/internal/engine/netx/errorx/errorx_test.go b/internal/errorsx/errorsx_test.go similarity index 99% rename from internal/engine/netx/errorx/errorx_test.go rename to internal/errorsx/errorsx_test.go index 08de2e0..252784f 100644 --- a/internal/engine/netx/errorx/errorx_test.go +++ b/internal/errorsx/errorsx_test.go @@ -1,4 +1,4 @@ -package errorx +package errorsx import ( "context" diff --git a/internal/netxlite/legacy.go b/internal/netxlite/legacy.go index c3af816..72eaeee 100644 --- a/internal/netxlite/legacy.go +++ b/internal/netxlite/legacy.go @@ -4,7 +4,7 @@ import ( "errors" "strings" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) // reduceErrors finds a known error in a list of errors since @@ -27,7 +27,7 @@ func reduceErrors(errorslist []error) error { // the user has no IPv6 connectivity, an IPv6 error is going to // appear later in the list of errors. for _, err := range errorslist { - var wrapper *errorx.ErrWrapper + var wrapper *errorsx.ErrWrapper if errors.As(err, &wrapper) && !strings.HasPrefix( err.Error(), "unknown_failure", ) { diff --git a/internal/netxlite/legacy_test.go b/internal/netxlite/legacy_test.go index 4132168..b21d356 100644 --- a/internal/netxlite/legacy_test.go +++ b/internal/netxlite/legacy_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" + "github.com/ooni/probe-cli/v3/internal/errorsx" ) func TestReduceErrors(t *testing.T) { @@ -31,15 +31,15 @@ func TestReduceErrors(t *testing.T) { }) t.Run("multiple errors with meaningful ones", func(t *testing.T) { err1 := errors.New("mocked error #1") - err2 := &errorx.ErrWrapper{ + err2 := &errorsx.ErrWrapper{ Failure: "unknown_failure: antani", } - err3 := &errorx.ErrWrapper{ - Failure: errorx.FailureConnectionRefused, + err3 := &errorsx.ErrWrapper{ + Failure: errorsx.FailureConnectionRefused, } err4 := errors.New("mocked error #3") result := reduceErrors([]error{err1, err2, err3, err4}) - if result.Error() != errorx.FailureConnectionRefused { + if result.Error() != errorsx.FailureConnectionRefused { t.Fatal("wrong result") } })