Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove cockroach db errors #20386

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package baseapp

import (
"context"
"errors"
"fmt"
"sort"
"strings"
"time"

"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cosmos/gogoproto/proto"
Expand Down
2 changes: 1 addition & 1 deletion baseapp/abci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package baseapp
import (
"bytes"
"context"
"errors"
"fmt"
"slices"

"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
cryptoenc "github.com/cometbft/cometbft/crypto/encoding"
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package baseapp

import (
"context"
"errors"
"fmt"
"math"
"sort"
"strconv"
"sync"

"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cometbft/cometbft/crypto/tmhash"
Expand Down
2 changes: 1 addition & 1 deletion client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package client
import (
"context"
"crypto/tls"
"errors"
"fmt"
"slices"
"strings"

"github.com/cockroachdb/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"google.golang.org/grpc"
Expand Down
2 changes: 1 addition & 1 deletion client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package client

import (
"context"
"errors"
"fmt"
"strings"

"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types"
rpcclient "github.com/cometbft/cometbft/rpc/client"
"google.golang.org/grpc/codes"
Expand Down
2 changes: 1 addition & 1 deletion client/v2/autocli/flag/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"encoding/base64"
"encoding/hex"
"errors"
"os"

"github.com/cockroachdb/errors"
"google.golang.org/protobuf/reflect/protoreflect"
)

Expand Down
2 changes: 1 addition & 1 deletion client/v2/autocli/flag/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package flag

import (
"context"
"errors"
"fmt"
"strings"

"github.com/cockroachdb/errors"
"github.com/spf13/pflag"
"google.golang.org/protobuf/reflect/protoreflect"

Expand Down
5 changes: 2 additions & 3 deletions client/v2/autocli/flag/maps/generic.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package maps

import (
"fmt"
"strings"

"github.com/cockroachdb/errors"
)

type genericMapValueOptions[K comparable, V any] struct {
Expand Down Expand Up @@ -31,7 +30,7 @@ func (gm *genericMapValue[K, V]) Set(val string) error {
for _, pair := range ss {
kv := strings.SplitN(pair, "=", 2)
if len(kv) != 2 {
return errors.Errorf("%s must be formatted as key=value", pair)
return fmt.Errorf("%s must be formatted as key=value", pair)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %w for error wrapping.

To wrap errors correctly and preserve the original error context, use %w instead of %v in fmt.Errorf.

- return fmt.Errorf("%s must be formatted as key=value", pair)
+ return fmt.Errorf("%s must be formatted as key=value: %w", pair, err)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return fmt.Errorf("%s must be formatted as key=value", pair)
return fmt.Errorf("%s must be formatted as key=value: %w", pair, err)

}
key, err := gm.Options.keyParser(kv[0])
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions client/v2/autocli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

"github.com/cockroachdb/errors"
gogoproto "github.com/cosmos/gogoproto/proto"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -69,7 +68,7 @@ func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autoc

descriptor, err := b.FileResolver.FindDescriptorByName(protoreflect.FullName(cmdDescriptor.Service))
if err != nil {
return errors.Errorf("can't find service %s: %v", cmdDescriptor.Service, err)
return fmt.Errorf("can't find service %s: %v", cmdDescriptor.Service, err)
}
service := descriptor.(protoreflect.ServiceDescriptor)
methods := service.Methods()
Expand Down
4 changes: 2 additions & 2 deletions client/v2/autocli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/math"
"cosmossdk.io/x/tx/signing/aminojson"
"github.com/cockroachdb/errors"

"github.com/spf13/cobra"
"google.golang.org/protobuf/reflect/protoreflect"

Expand Down Expand Up @@ -62,7 +62,7 @@ func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *aut

descriptor, err := b.FileResolver.FindDescriptorByName(protoreflect.FullName(cmdDescriptor.Service))
if err != nil {
return errors.Errorf("can't find service %s: %v", cmdDescriptor.Service, err)
return fmt.Errorf("can't find service %s: %w", cmdDescriptor.Service, err)
}

service := descriptor.(protoreflect.ServiceDescriptor)
Expand Down
2 changes: 1 addition & 1 deletion client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
cosmossdk.io/x/gov v0.0.0-20231113122742-912390d5fc4a
cosmossdk.io/x/tx v0.13.3
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.11.1
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.51.0
github.com/manifoldco/promptui v0.9.0 // indirect
Expand Down
6 changes: 3 additions & 3 deletions depinject/check_type.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package depinject

import (
"fmt"
"reflect"
"strings"
"unicode"

"github.com/cockroachdb/errors"
"golang.org/x/exp/slices"
)

Expand All @@ -21,12 +21,12 @@ func isExportedType(typ reflect.Type) error {
pkgPath := typ.PkgPath()
if name != "" && pkgPath != "" {
if unicode.IsLower([]rune(name)[0]) {
return errors.Errorf("type must be exported: %s", typ)
return fmt.Errorf("type must be exported: %s", typ)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %w for error wrapping.

To wrap errors correctly and preserve the original error context, use %w instead of %v in fmt.Errorf.

- return fmt.Errorf("type must be exported: %s", typ)
+ return fmt.Errorf("type must be exported: %w", typ)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return fmt.Errorf("type must be exported: %s", typ)
return fmt.Errorf("type must be exported: %w", typ)

}

pkgParts := strings.Split(pkgPath, "/")
if slices.Contains(pkgParts, "internal") {
return errors.Errorf("type must not come from an internal package: %s", typ)
return fmt.Errorf("type must not come from an internal package: %s", typ)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %w for error wrapping.

To wrap errors correctly and preserve the original error context, use %w instead of %v in fmt.Errorf.

- return fmt.Errorf("type must not come from an internal package: %s", typ)
+ return fmt.Errorf("type must not come from an internal package: %w", typ)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return fmt.Errorf("type must not come from an internal package: %s", typ)
return fmt.Errorf("type must not come from an internal package: %w", typ)

}

return nil
Expand Down
11 changes: 6 additions & 5 deletions depinject/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package depinject

import (
"errors"
"reflect"

"github.com/cockroachdb/errors"
pkgerrors "github.com/pkg/errors"
)

// Config is a functional configuration of a container.
Expand Down Expand Up @@ -33,7 +34,7 @@
func ProvideInModule(moduleName string, providers ...interface{}) Config {
return containerConfig(func(ctr *container) error {
if moduleName == "" {
return errors.Errorf("expected non-empty module name")
return errors.New("expected non-empty module name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing more context in the error message.

-			return errors.New("expected non-empty module name")
+			return errors.New("ProvideInModule: expected non-empty module name")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return errors.New("expected non-empty module name")
return errors.New("ProvideInModule: expected non-empty module name")

}

return provide(ctr, ctr.moduleKeyContext.createOrGetModuleKey(moduleName), providers)
Expand All @@ -44,11 +45,11 @@
for _, c := range providers {
rc, err := extractProviderDescriptor(c)
if err != nil {
return errors.WithStack(err)
return pkgerrors.WithStack(err)
}
_, err = ctr.addNode(&rc, key)
if err != nil {
return errors.WithStack(err)
return pkgerrors.WithStack(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use consistent import alias for pkgerrors.WithStack.

-			return pkgerrors.WithStack(err)
+			return errors.WithStack(err)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return pkgerrors.WithStack(err)
}
_, err = ctr.addNode(&rc, key)
if err != nil {
return errors.WithStack(err)
return pkgerrors.WithStack(err)
return errors.WithStack(err)
}
_, err = ctr.addNode(&rc, key)
if err != nil {
return pkgerrors.WithStack(err)

}
}
return nil
Expand Down Expand Up @@ -80,7 +81,7 @@
func InvokeInModule(moduleName string, invokers ...interface{}) Config {
return containerConfig(func(ctr *container) error {
if moduleName == "" {
return errors.Errorf("expected non-empty module name")
return errors.New("expected non-empty module name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing more context in the error message.

-			return errors.New("expected non-empty module name")
+			return errors.New("InvokeInModule: expected non-empty module name")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return errors.New("expected non-empty module name")
return errors.New("InvokeInModule: expected non-empty module name")

}

return invoke(ctr, ctr.moduleKeyContext.createOrGetModuleKey(moduleName), invokers)
Expand All @@ -91,7 +92,7 @@
for _, c := range invokers {
rc, err := extractInvokerDescriptor(c)
if err != nil {
return errors.WithStack(err)

Check failure on line 95 in depinject/config.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: errors.WithStack

Check failure on line 95 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: errors.WithStack

Check failure on line 95 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: errors.WithStack

Check failure on line 95 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: errors.WithStack

Check failure on line 95 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: errors.WithStack
}
err = ctr.addInvoker(&rc, key)
if err != nil {
Expand Down Expand Up @@ -151,7 +152,7 @@
for _, v := range values {
err := ctr.supply(reflect.ValueOf(v), loc)
if err != nil {
return errors.WithStack(err)

Check failure on line 155 in depinject/config.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: errors.WithStack

Check failure on line 155 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: errors.WithStack

Check failure on line 155 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: errors.WithStack

Check failure on line 155 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: errors.WithStack

Check failure on line 155 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: errors.WithStack
}
}
return nil
Expand All @@ -162,7 +163,7 @@
// fail immediately.
func Error(err error) Config {
return containerConfig(func(*container) error {
return errors.WithStack(err)

Check failure on line 166 in depinject/config.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: errors.WithStack

Check failure on line 166 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: errors.WithStack

Check failure on line 166 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: errors.WithStack

Check failure on line 166 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: errors.WithStack

Check failure on line 166 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: errors.WithStack
})
}

Expand All @@ -172,7 +173,7 @@
for _, opt := range opts {
err := opt.apply(ctr)
if err != nil {
return errors.WithStack(err)

Check failure on line 176 in depinject/config.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: errors.WithStack

Check failure on line 176 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: errors.WithStack

Check failure on line 176 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: errors.WithStack

Check failure on line 176 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: errors.WithStack

Check failure on line 176 in depinject/config.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: errors.WithStack
}
}
return nil
Expand Down
18 changes: 8 additions & 10 deletions depinject/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"fmt"
"reflect"

"github.com/cockroachdb/errors"

"cosmossdk.io/depinject/internal/graphviz"
)

Expand Down Expand Up @@ -63,7 +61,7 @@ func (c *container) call(provider *providerDescriptor, moduleKey *moduleKey) ([]
markGraphNodeAsFailed(graphNode)

if c.callerMap[loc] {
return nil, errors.Errorf("cyclic dependency: %s -> %s", loc.Name(), loc.Name())
return nil, fmt.Errorf("cyclic dependency: %s -> %s", loc.Name(), loc.Name())
}

c.callerMap[loc] = true
Expand All @@ -87,7 +85,7 @@ func (c *container) call(provider *providerDescriptor, moduleKey *moduleKey) ([]

out, err := provider.Fn(inVals)
if err != nil {
return nil, errors.Wrapf(err, "error calling provider %s", loc)
return nil, fmt.Errorf("error calling provider %s: %w", loc, err)
}

markGraphNodeAsUsed(graphNode)
Expand Down Expand Up @@ -296,7 +294,7 @@ func (c *container) addNode(provider *providerDescriptor, key *moduleKey) (inter
}

if hasOwnModuleKeyParam {
return nil, errors.Errorf("%T and %T must not be declared as dependencies on the same provided",
return nil, fmt.Errorf("%T and %T must not be declared as dependencies on the same provided",
ModuleKey{}, OwnModuleKey{})
}

Expand All @@ -317,7 +315,7 @@ func (c *container) addNode(provider *providerDescriptor, key *moduleKey) (inter

existing, ok := c.resolverByType(typ)
if ok {
return nil, errors.Errorf("duplicate provision of type %v by module-scoped provider %s\n\talready provided by %s",
return nil, fmt.Errorf("duplicate provision of type %v by module-scoped provider %s\n\talready provided by %s",
typ, provider.Location, existing.describeLocation())
}

Expand Down Expand Up @@ -378,7 +376,7 @@ func (c *container) resolve(in providerInput, moduleKey *moduleKey, caller Locat

if in.Type == moduleKeyType {
if moduleKey == nil {
return reflect.Value{}, errors.Errorf("trying to resolve %T for %s but not inside of any module's scope", moduleKey, caller)
return reflect.Value{}, fmt.Errorf("trying to resolve %T for %s but not inside of any module's scope", moduleKey, caller)
}
c.logf("Providing ModuleKey %s", moduleKey.name)
markGraphNodeAsUsed(typeGraphNode)
Expand All @@ -387,7 +385,7 @@ func (c *container) resolve(in providerInput, moduleKey *moduleKey, caller Locat

if in.Type == ownModuleKeyType {
if moduleKey == nil {
return reflect.Value{}, errors.Errorf("trying to resolve %T for %s but not inside of any module's scope", moduleKey, caller)
return reflect.Value{}, fmt.Errorf("trying to resolve %T for %s but not inside of any module's scope", moduleKey, caller)
}
c.logf("Providing OwnModuleKey %s", moduleKey.name)
markGraphNodeAsUsed(typeGraphNode)
Expand All @@ -406,7 +404,7 @@ func (c *container) resolve(in providerInput, moduleKey *moduleKey, caller Locat
}

markGraphNodeAsFailed(typeGraphNode)
return reflect.Value{}, errors.Errorf("can't resolve type %v for %s:\n%s",
return reflect.Value{}, fmt.Errorf("can't resolve type %v for %s:\n%s",
fullyQualifiedTypeName(in.Type), caller, c.formatResolveStack())
}

Expand Down Expand Up @@ -475,7 +473,7 @@ func (c *container) build(loc Location, outputs ...interface{}) error {

sn, ok := node.(*simpleProvider)
if !ok {
return errors.Errorf("cannot run module-scoped provider as an invoker")
return stderrors.New("cannot run module-scoped provider as an invoker")
}

c.logf("Building container")
Expand Down
4 changes: 1 addition & 3 deletions depinject/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package depinject
import (
"fmt"
"reflect"

"github.com/cockroachdb/errors"
)

// ErrMultipleImplicitInterfaceBindings defines an error condition where an attempt was made to implicitly bind
Expand Down Expand Up @@ -63,6 +61,6 @@ func (err ErrNoTypeForExplicitBindingFound) Error() string {
}

func duplicateDefinitionError(typ reflect.Type, duplicateLoc Location, existingLoc string) error {
return errors.Errorf("duplicate provision of type %v by %s\n\talready provided by %s",
return fmt.Errorf("duplicate provision of type %v by %s\n\talready provided by %s",
typ, duplicateLoc, existingLoc)
}
Comment on lines +64 to 66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %w for error wrapping.

To wrap errors correctly and preserve the original error context, use %w instead of %v in fmt.Errorf.

- return fmt.Errorf("duplicate provision of type %v by %s\n\talready provided by %s",
- typ, duplicateLoc, existingLoc)
+ return fmt.Errorf("duplicate provision of type %v by %s\n\talready provided by %w",
+ typ, duplicateLoc, existingLoc)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return fmt.Errorf("duplicate provision of type %v by %s\n\talready provided by %s",
typ, duplicateLoc, existingLoc)
}
return fmt.Errorf("duplicate provision of type %v by %s\n\talready provided by %w",
typ, duplicateLoc, existingLoc)

9 changes: 2 additions & 7 deletions depinject/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.20

require (
cosmossdk.io/api v0.7.5
github.com/cockroachdb/errors v1.11.1
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb
google.golang.org/protobuf v1.34.1
Expand All @@ -14,21 +14,16 @@ require (
)

require (
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading