diff --git a/authentication.go b/authentication.go index c04ee448..77750b86 100644 --- a/authentication.go +++ b/authentication.go @@ -2,9 +2,9 @@ package pgproto3 import ( "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) const ( @@ -31,7 +31,7 @@ func (dst *Authentication) Decode(src []byte) error { case AuthTypeMD5Password: copy(dst.Salt[:], src[4:8]) default: - return fmt.Errorf("unknown authentication type: %d", dst.Type) + return errors.Errorf("unknown authentication type: %d", dst.Type) } return nil diff --git a/backend.go b/backend.go index bf96ba95..9a7ef342 100644 --- a/backend.go +++ b/backend.go @@ -2,10 +2,10 @@ package pgproto3 import ( "encoding/binary" - "fmt" "io" "github.com/jackc/pgx/chunkreader" + "github.com/pkg/errors" ) type Backend struct { @@ -88,7 +88,7 @@ func (b *Backend) Receive() (FrontendMessage, error) { case 'X': msg = &b.terminate default: - return nil, fmt.Errorf("unknown message type: %c", msgType) + return nil, errors.Errorf("unknown message type: %c", msgType) } msgBody, err := b.cr.Next(bodyLen) diff --git a/frontend.go b/frontend.go index 630a5cba..c8ab5f15 100644 --- a/frontend.go +++ b/frontend.go @@ -2,10 +2,10 @@ package pgproto3 import ( "encoding/binary" - "fmt" "io" "github.com/jackc/pgx/chunkreader" + "github.com/pkg/errors" ) type Frontend struct { @@ -100,7 +100,7 @@ func (b *Frontend) Receive() (BackendMessage, error) { case 'Z': msg = &b.readyForQuery default: - return nil, fmt.Errorf("unknown message type: %c", msgType) + return nil, errors.Errorf("unknown message type: %c", msgType) } msgBody, err := b.cr.Next(bodyLen) diff --git a/startup_message.go b/startup_message.go index 4e2df27d..6c5d4f99 100644 --- a/startup_message.go +++ b/startup_message.go @@ -4,9 +4,9 @@ import ( "bytes" "encoding/binary" "encoding/json" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) const ( @@ -23,18 +23,18 @@ func (*StartupMessage) Frontend() {} func (dst *StartupMessage) Decode(src []byte) error { if len(src) < 4 { - return fmt.Errorf("startup message too short") + return errors.Errorf("startup message too short") } dst.ProtocolVersion = binary.BigEndian.Uint32(src) rp := 4 if dst.ProtocolVersion == sslRequestNumber { - return fmt.Errorf("can't handle ssl connection request") + return errors.Errorf("can't handle ssl connection request") } if dst.ProtocolVersion != ProtocolVersionNumber { - return fmt.Errorf("Bad startup message version number. Expected %d, got %d", ProtocolVersionNumber, dst.ProtocolVersion) + return errors.Errorf("Bad startup message version number. Expected %d, got %d", ProtocolVersionNumber, dst.ProtocolVersion) } dst.Parameters = make(map[string]string) @@ -57,7 +57,7 @@ func (dst *StartupMessage) Decode(src []byte) error { if len(src[rp:]) == 1 { if src[rp] != 0 { - return fmt.Errorf("Bad startup message last byte. Expected 0, got %d", src[rp]) + return errors.Errorf("Bad startup message last byte. Expected 0, got %d", src[rp]) } break }