Skip to content

Commit

Permalink
messages/protobuf: Use xerrors package
Browse files Browse the repository at this point in the history
According to issue hyperledger-labs#106, the code base should eventually switch to use
`golang.org/x/xerrors` package if favor of built-in `fmt` and `errors`
packages. Switch this package to use `xerrors` before doing further
changes.

Signed-off-by: Sergey Fedorov <sergey.fedorov@neclab.eu>
  • Loading branch information
Sergey Fedorov committed Jan 9, 2020
1 parent ee71cdf commit 073e5a3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ require (
github.com/spf13/viper v1.3.1
github.com/stretchr/objx v0.0.0-20180825064932-ef50b0de2877 // indirect
github.com/stretchr/testify v1.2.2
golang.org/x/net v0.0.0-20181217023233-e147a9138326
golang.org/x/net v0.0.0-20181217023233-e147a9138326 // indirect
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f
golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
google.golang.org/genproto v0.0.0-20181217193449-09cd0d62f46c // indirect
google.golang.org/grpc v1.18.0
gopkg.in/yaml.v2 v2.2.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20181217193449-09cd0d62f46c h1:e2ImTtBojL8kivfJ1B6rjiMeRj3yfUuK7k+HD1+D1lw=
Expand Down
6 changes: 3 additions & 3 deletions messages/protobuf/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package protobuf

import (
fmt "fmt"
"golang.org/x/xerrors"

"github.com/golang/protobuf/proto"

Expand All @@ -32,7 +32,7 @@ func NewImpl() messages.MessageImpl {
func (*impl) NewFromBinary(data []byte) (messages.Message, error) {
msg := &pb.Message{}
if err := proto.Unmarshal(data, msg); err != nil {
return nil, fmt.Errorf("failed to unmarshal message wrapper: %s", err)
return nil, xerrors.Errorf("failed to unmarshal message wrapper: %w", err)
}

switch t := msg.Type.(type) {
Expand All @@ -53,7 +53,7 @@ func (*impl) NewFromBinary(data []byte) (messages.Message, error) {
reply.set(t.Reply)
return reply, nil
default:
return nil, fmt.Errorf("unknown message type")
return nil, xerrors.New("unknown message type")
}
}

Expand Down

0 comments on commit 073e5a3

Please sign in to comment.