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

refactor: use errors.New to replace fmt.Errorf with no parameters #21394

Merged
merged 2 commits into from
Aug 25, 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
6 changes: 3 additions & 3 deletions schema/appdata/async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package appdata

import (
"context"
"fmt"
"errors"
"sync"
"testing"
)
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestAsyncListenerMux(t *testing.T) {
calls1 = append(calls1, name)
})
listener1.Commit = func(data CommitData) (completionCallback func() error, err error) {
return nil, fmt.Errorf("error")
return nil, errors.New("error")
}
listener2 := callCollector(2, func(name string, _ int, _ Packet) {
calls2 = append(calls2, name)
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestAsyncListener(t *testing.T) {
})

listener.OnKVPair = func(updates KVPairData) error {
return fmt.Errorf("error")
return errors.New("error")
}

res := AsyncListener(AsyncListenerOptions{BufferSize: 16}, listener)
Expand Down
4 changes: 2 additions & 2 deletions server/v2/stf/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package stf

import (
"context"
"fmt"
"errors"
)

// getExecutionCtxFromContext tries to get the execution context from the given go context.
Expand All @@ -16,5 +16,5 @@ func getExecutionCtxFromContext(ctx context.Context) (*executionContext, error)
return value, nil
}

return nil, fmt.Errorf("failed to get executionContext from context")
return nil, errors.New("failed to get executionContext from context")
}
4 changes: 2 additions & 2 deletions server/v2/store/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ func (s *StoreComponent[T]) LoadArchiveCmd() *cobra.Command {

savedSnapshot := <-quitChan
if savedSnapshot == nil {
return fmt.Errorf("failed to save snapshot")
return errors.New("failed to save snapshot")
}

if !reflect.DeepEqual(&snapshot, savedSnapshot) {
_ = snapshotStore.Delete(snapshot.Height, snapshot.Format)
return fmt.Errorf("invalid archive, the saved snapshot is not equal to the original one")
return errors.New("invalid archive, the saved snapshot is not equal to the original one")
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions store/v2/root/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func CreateRootStore(opts *FactoryOptions) (store.RootStore, error) {
case SCTypeIavl:
return iavl.NewIavlTree(db.NewPrefixDB(opts.SCRawDB, []byte(key)), opts.Logger, storeOpts.IavlConfig), nil
case SCTypeIavlV2:
return nil, fmt.Errorf("iavl v2 not supported")
return nil, errors.New("iavl v2 not supported")
default:
return nil, fmt.Errorf("unsupported commitment store type")
return nil, errors.New("unsupported commitment store type")
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions store/v2/root/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ func (s *Store) LoadVersion(version uint64) error {
// NOTE: It cannot be called while the store is migrating.
func (s *Store) LoadVersionAndUpgrade(version uint64, upgrades *corestore.StoreUpgrades) error {
if upgrades == nil {
return fmt.Errorf("upgrades cannot be nil")
return errors.New("upgrades cannot be nil")
}

if s.telemetry != nil {
defer s.telemetry.MeasureSince(time.Now(), "root_store", "load_version_and_upgrade")
}

if s.isMigrating {
return fmt.Errorf("cannot upgrade while migrating")
return errors.New("cannot upgrade while migrating")
}

if err := s.loadVersion(version, upgrades); err != nil {
Expand Down Expand Up @@ -283,7 +283,7 @@ func (s *Store) loadVersion(v uint64, upgrades *corestore.StoreUpgrades) error {
// if upgrades are provided, we need to load the version and apply the upgrades
upgradeableStore, ok := s.stateCommitment.(store.UpgradeableStore)
if !ok {
return fmt.Errorf("SC store does not support upgrades")
return errors.New("SC store does not support upgrades")
}
if err := upgradeableStore.LoadVersionAndUpgrade(v, upgrades); err != nil {
return fmt.Errorf("failed to load SS version with upgrades %d: %w", v, err)
Expand Down
3 changes: 2 additions & 1 deletion x/distribution/keeper/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"errors"
"fmt"

"github.com/pkg/errors"
Expand Down Expand Up @@ -144,7 +145,7 @@ func (k Keeper) decrementReferenceCount(ctx context.Context, valAddr sdk.ValAddr
}

if historical.ReferenceCount == 0 {
return fmt.Errorf("cannot set negative reference count")
return errors.New("cannot set negative reference count")
}
historical.ReferenceCount--
if historical.ReferenceCount == 0 {
Expand Down
4 changes: 2 additions & 2 deletions x/genutil/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package genutil

import (
"context"
"fmt"
"errors"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -22,7 +22,7 @@ func InitGenesis(
txEncodingConfig client.TxEncodingConfig,
) (validatorUpdates []module.ValidatorUpdate, err error) {
if deliverTx == nil {
return nil, fmt.Errorf("deliverTx (genesis.TxHandler) not defined, verify x/genutil wiring")
return nil, errors.New("deliverTx (genesis.TxHandler) not defined, verify x/genutil wiring")
}

if len(genesisState.GenTxs) > 0 {
Expand Down
Loading