2
0

Use github.com/pkg/errors

This commit is contained in:
Jack Christensen
2017-06-04 21:30:03 -05:00
parent 8e404a02a3
commit ffa9ff2213
4 changed files with 11 additions and 11 deletions
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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)
+5 -5
View File
@@ -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
}