diff --git a/connection.go b/connection.go index 75d3ef3..40ee71f 100644 --- a/connection.go +++ b/connection.go @@ -40,33 +40,6 @@ const ( StatusUnknown Status = "" ) -// UnpackError returns error with possibility to access RawMessage when -// connection failed to unpack message -type UnpackError struct { - Err error - RawMessage []byte -} - -func (e *UnpackError) Error() string { - return e.Err.Error() -} - -func (e *UnpackError) Unwrap() error { - return e.Err -} - -type PackError struct { - Err error -} - -func (e *PackError) Error() string { - return e.Err.Error() -} - -func (e *PackError) Unwrap() error { - return e.Err -} - // Connection represents an ISO 8583 Connection. Connection may be used // by multiple goroutines simultaneously. type Connection struct { @@ -413,7 +386,7 @@ func (c *Connection) writeMessage(w io.Writer, message *iso8583.Message) error { // default message writer packed, err := message.Pack() if err != nil { - return utils.NewSafeError(&PackError{err}, "failed to pack message") + return fmt.Errorf("packing message: %w", err) } // create buffer for header and packed message so we can write it to @@ -536,7 +509,7 @@ func (c *Connection) writeLoop() { if err != nil { c.handleError(fmt.Errorf("writing message: %w", err)) - var packErr *PackError + var packErr *iso8583.PackError if errors.As(err, &packErr) { // let caller know that the message was not sent because of pack error. // We don't set all type of errors to errCh as this case is handled @@ -587,9 +560,9 @@ func (c *Connection) readLoop() { if err != nil { c.handleError(utils.NewSafeError(err, "failed to read message from connection")) - // if err is ErrUnpack, we can still continue reading + // if err is UnpackError, we can still continue reading // from the connection - var unpackErr *UnpackError + var unpackErr *iso8583.UnpackError if errors.As(err, &unpackErr) { continue } @@ -635,11 +608,7 @@ func (c *Connection) readMessage(r io.Reader) (*iso8583.Message, error) { message := iso8583.NewMessage(c.spec) err = message.Unpack(rawMessage) if err != nil { - unpackErr := &UnpackError{ - Err: err, - RawMessage: rawMessage, - } - return nil, fmt.Errorf("unpacking message: %w", unpackErr) + return nil, fmt.Errorf("unpacking message: %w", err) } return message, nil diff --git a/connection_test.go b/connection_test.go index 3064ca9..990b6ac 100644 --- a/connection_test.go +++ b/connection_test.go @@ -289,7 +289,7 @@ func TestClient_Send(t *testing.T) { // then Send should return PackError require.Error(t, err) - var packError *connection.PackError + var packError *iso8583.PackError require.ErrorAs(t, err, &packError) }) @@ -367,7 +367,7 @@ func TestClient_Send(t *testing.T) { mu.Lock() defer mu.Unlock() - var unpackErr *connection.UnpackError + var unpackErr *iso8583.UnpackError if errors.As(handledError, &unpackErr) { require.EqualError(t, handledError, "failed to read message from connection") require.EqualError(t, unpackErr, "failed to unpack field 63: no specification found") diff --git a/go.mod b/go.mod index 91183df..d169903 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/moov-io/iso8583-connection go 1.19 require ( - github.com/moov-io/iso8583 v0.18.2 + github.com/moov-io/iso8583 v0.18.3 github.com/stretchr/testify v1.8.4 ) @@ -12,6 +12,6 @@ require ( github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/yerden/go-util v1.1.4 // indirect - golang.org/x/text v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 918b62a..d63def4 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,10 @@ github.com/moov-io/iso8583 v0.18.1 h1:J0amw2rhoTv2l5nvY7n4Ee4A34SSBrZESfrZ+Dvke0 github.com/moov-io/iso8583 v0.18.1/go.mod h1:rqnoLk9z66a2S6OAo6oeVJsGrGwr/MQkx2G7frxS5RI= github.com/moov-io/iso8583 v0.18.2 h1:7D/zGxhV7YK23V1SfARU/JcJFVAW9jp0j1k1W5z4WyY= github.com/moov-io/iso8583 v0.18.2/go.mod h1:yq1HVUdtNG+NXY0YIaD4od/QOKCCOSk6/ygU2aTE/E0= +github.com/moov-io/iso8583 v0.18.3-0.20230720140054-1b1d36aa2970 h1:PdUPxYek+MeOea1GfjATYLSDZolsS6IDoUbAsIq6Its= +github.com/moov-io/iso8583 v0.18.3-0.20230720140054-1b1d36aa2970/go.mod h1:QPxDQTxKJPjECpK8vCsh7TpwvKyIrw3tXN/lrdATzCA= +github.com/moov-io/iso8583 v0.18.3 h1:RYr/zoNxeRcLpJ1VjJ8e8yC0fRK5+xFqKqpnyMTz3+A= +github.com/moov-io/iso8583 v0.18.3/go.mod h1:QPxDQTxKJPjECpK8vCsh7TpwvKyIrw3tXN/lrdATzCA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= @@ -20,6 +24,8 @@ golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=