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 ( import (
"encoding/binary" "encoding/binary"
"fmt"
"github.com/jackc/pgx/pgio" "github.com/jackc/pgx/pgio"
"github.com/pkg/errors"
) )
const ( const (
@@ -31,7 +31,7 @@ func (dst *Authentication) Decode(src []byte) error {
case AuthTypeMD5Password: case AuthTypeMD5Password:
copy(dst.Salt[:], src[4:8]) copy(dst.Salt[:], src[4:8])
default: default:
return fmt.Errorf("unknown authentication type: %d", dst.Type) return errors.Errorf("unknown authentication type: %d", dst.Type)
} }
return nil return nil
+2 -2
View File
@@ -2,10 +2,10 @@ package pgproto3
import ( import (
"encoding/binary" "encoding/binary"
"fmt"
"io" "io"
"github.com/jackc/pgx/chunkreader" "github.com/jackc/pgx/chunkreader"
"github.com/pkg/errors"
) )
type Backend struct { type Backend struct {
@@ -88,7 +88,7 @@ func (b *Backend) Receive() (FrontendMessage, error) {
case 'X': case 'X':
msg = &b.terminate msg = &b.terminate
default: 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) msgBody, err := b.cr.Next(bodyLen)
+2 -2
View File
@@ -2,10 +2,10 @@ package pgproto3
import ( import (
"encoding/binary" "encoding/binary"
"fmt"
"io" "io"
"github.com/jackc/pgx/chunkreader" "github.com/jackc/pgx/chunkreader"
"github.com/pkg/errors"
) )
type Frontend struct { type Frontend struct {
@@ -100,7 +100,7 @@ func (b *Frontend) Receive() (BackendMessage, error) {
case 'Z': case 'Z':
msg = &b.readyForQuery msg = &b.readyForQuery
default: 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) msgBody, err := b.cr.Next(bodyLen)
+5 -5
View File
@@ -4,9 +4,9 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"fmt"
"github.com/jackc/pgx/pgio" "github.com/jackc/pgx/pgio"
"github.com/pkg/errors"
) )
const ( const (
@@ -23,18 +23,18 @@ func (*StartupMessage) Frontend() {}
func (dst *StartupMessage) Decode(src []byte) error { func (dst *StartupMessage) Decode(src []byte) error {
if len(src) < 4 { if len(src) < 4 {
return fmt.Errorf("startup message too short") return errors.Errorf("startup message too short")
} }
dst.ProtocolVersion = binary.BigEndian.Uint32(src) dst.ProtocolVersion = binary.BigEndian.Uint32(src)
rp := 4 rp := 4
if dst.ProtocolVersion == sslRequestNumber { 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 { 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) dst.Parameters = make(map[string]string)
@@ -57,7 +57,7 @@ func (dst *StartupMessage) Decode(src []byte) error {
if len(src[rp:]) == 1 { if len(src[rp:]) == 1 {
if src[rp] != 0 { 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 break
} }