Skip to content

Commit

Permalink
Merge branch 'main' into store/pruning_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
cool-develope authored May 21, 2024
2 parents f97109c + b17ccd8 commit ae7a468
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 81 deletions.
4 changes: 4 additions & 0 deletions errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### API Breaking

* [#20402](https://github.com/cosmos/cosmos-sdk/pull/20402) Remove Grpc error codes from the error package. This is done in order to keep the dependency graph of errors minimal

## [v1.0.1](https://github.com/cosmos/cosmos-sdk/releases/tag/errors%2Fv1.0.1)

### Improvements
Expand Down
39 changes: 1 addition & 38 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import (
"reflect"

"github.com/pkg/errors"
grpccodes "google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"
)

// UndefinedCodespace when we explicitly declare no codespace
const UndefinedCodespace = "undefined"

var (
// errInternal should never be exposed, but we reserve this code for non-specified errors
errInternal = Register(UndefinedCodespace, 1, "internal")

// ErrStopIterating is used to break out of an iteration
ErrStopIterating = Register(UndefinedCodespace, 2, "stop iterating")
Expand All @@ -32,18 +28,11 @@ var (
//
// Use this function only during a program startup phase.
func Register(codespace string, code uint32, description string) *Error {
return RegisterWithGRPCCode(codespace, code, grpccodes.Unknown, description)
}

// RegisterWithGRPCCode is a version of Register that associates a gRPC error
// code with a registered error.
func RegisterWithGRPCCode(codespace string, code uint32, grpcCode grpccodes.Code, description string) *Error {
// TODO - uniqueness is (codespace, code) combo
if e := getUsed(codespace, code); e != nil {
panic(fmt.Sprintf("error with code %d is already registered: %q", code, e.desc))
}

err := &Error{codespace: codespace, code: code, desc: description, grpcCode: grpcCode}
err := &Error{codespace: codespace, code: code, desc: description}
setUsed(err)

return err
Expand Down Expand Up @@ -94,7 +83,6 @@ type Error struct {
codespace string
code uint32
desc string
grpcCode grpccodes.Code
}

// New is an alias for Register.
Expand Down Expand Up @@ -154,10 +142,6 @@ func (e *Error) Wrap(desc string) error { return Wrap(e, desc) }
// It's a handy function to call Wrapf with sdk errors.
func (e *Error) Wrapf(desc string, args ...interface{}) error { return Wrapf(e, desc, args...) }

func (e *Error) GRPCStatus() *grpcstatus.Status {
return grpcstatus.Newf(e.grpcCode, "codespace %s code %d: %s", e.codespace, e.code, e.desc)
}

func isNilErr(err error) bool {
// Reflect usage is necessary to correctly compare with
// a nil implementation of an error.
Expand Down Expand Up @@ -246,27 +230,6 @@ func (e *wrappedError) Unwrap() error {
return e.parent
}

// GRPCStatus gets the gRPC status from the wrapped error or returns an unknown gRPC status.
func (e *wrappedError) GRPCStatus() *grpcstatus.Status {
w := e.Cause()
for {
if hasStatus, ok := w.(interface {
GRPCStatus() *grpcstatus.Status
}); ok {
status := hasStatus.GRPCStatus()
return grpcstatus.New(status.Code(), fmt.Sprintf("%s: %s", status.Message(), e.msg))
}

x, ok := w.(causer)
if ok {
w = x.Cause()
}
if x == nil {
return grpcstatus.New(grpccodes.Unknown, e.msg)
}
}
}

// Recover captures a panic and stop its propagation. If panic happens it is
// transformed into a ErrPanic instance and assigned to given error. Call this
// function using defer in order to work as expected.
Expand Down
22 changes: 0 additions & 22 deletions errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (

"github.com/pkg/errors"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"
)

type errorsTestSuite struct {
Expand Down Expand Up @@ -209,23 +207,6 @@ func (s *errorsTestSuite) TestABCIError() {
s.Require().Equal("custom: unknown", ABCIError("unknown", 1, "custom").Error())
}

func (s *errorsTestSuite) TestGRPCStatus() {
s.Require().Equal(codes.Unknown, grpcstatus.Code(errInternal))
s.Require().Equal(codes.NotFound, grpcstatus.Code(ErrNotFound))

status, ok := grpcstatus.FromError(ErrNotFound)
s.Require().True(ok)
s.Require().Equal("codespace testtesttest code 38: not found", status.Message())

// test wrapping
s.Require().Equal(codes.Unimplemented, grpcstatus.Code(ErrNotSupported.Wrap("test")))
s.Require().Equal(codes.FailedPrecondition, grpcstatus.Code(ErrConflict.Wrapf("test %s", "foo")))

status, ok = grpcstatus.FromError(ErrNotFound.Wrap("test"))
s.Require().True(ok)
s.Require().Equal("codespace testtesttest code 38: not found: test", status.Message())
}

const testCodespace = "testtesttest"

var (
Expand Down Expand Up @@ -254,8 +235,5 @@ var (
ErrUnknownExtensionOptions = Register(testCodespace, 31, "unknown extension options")
ErrPackAny = Register(testCodespace, 33, "failed packing protobuf message to Any")
ErrLogic = Register(testCodespace, 35, "internal logic error")
ErrConflict = RegisterWithGRPCCode(testCodespace, 36, codes.FailedPrecondition, "conflict")
ErrNotSupported = RegisterWithGRPCCode(testCodespace, 37, codes.Unimplemented, "feature not supported")
ErrNotFound = RegisterWithGRPCCode(testCodespace, 38, codes.NotFound, "not found")
ErrIO = Register(testCodespace, 39, "Internal IO error")
)
5 changes: 0 additions & 5 deletions errors/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ go 1.20
require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.64.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 0 additions & 12 deletions errors/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
Expand All @@ -20,17 +19,6 @@ github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XF
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
8 changes: 4 additions & 4 deletions simapp/gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ schema = 3
version = "v1.6.2"
hash = "sha256-X7aNKLKZ7pJBG/wdP+TWuQnlNLNdbUDd+kC5kF4uBtU="
[mod."github.com/fatih/color"]
version = "v1.16.0"
hash = "sha256-Aq/SM28aPJVzvapllQ64R/DM4aZ5CHPewcm/AUJPyJQ="
version = "v1.17.0"
hash = "sha256-QsKMy3MsvjbYNcA9jP8w6c3wpmWDZ0079bybAEzmXR0="
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.4"
hash = "sha256-c1JKoRSndwwOyOxq9ddCe+8qn7mG9uRq2o/822x5O/c="
Expand Down Expand Up @@ -282,8 +282,8 @@ schema = 3
version = "v0.5.3"
hash = "sha256-5jQftEvEhL88yWeVnu+IZKzV5p9osZcgFmwP1zlrjzY="
[mod."github.com/hashicorp/go-plugin"]
version = "v1.6.0"
hash = "sha256-NeY86Z+qJwt0NPV4cNmWDiTryDPSiyKMkS1ivRX9ThE="
version = "v1.6.1"
hash = "sha256-HEeJ8TV67PcAuUnGCOHphFpZ/BShvJo5B6Obu3P7t8M="
[mod."github.com/hashicorp/go-safetemp"]
version = "v1.0.0"
hash = "sha256-g5i9m7FSRInQzZ4iRpIsoUu685AY7fppUwjhuZCezT8="
Expand Down

0 comments on commit ae7a468

Please sign in to comment.