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
+9 -9
View File
@@ -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
}
@@ -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) {
+4 -4
View File
@@ -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
+2 -2
View File
@@ -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" {