Skip to content

Commit

Permalink
refactor: add errorlint and make fmt.Errorf use %w to wrap error inst…
Browse files Browse the repository at this point in the history
…ead of %v (#878)
  • Loading branch information
hoank101 authored May 21, 2024
1 parent f6630da commit 3ddff28
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ linters:
- typecheck
- unconvert
- unused
- errorlint

issues:
exclude-use-default: false
Expand Down
4 changes: 2 additions & 2 deletions cmd/dymd/cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func InspectCmd(appExporter types.AppExporter, appCreator types.AppCreator, defa
height, _ := cmd.Flags().GetInt64(FlagHeight)
exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, false, []string{}, serverCtx.Viper)
if err != nil {
return fmt.Errorf("error exporting state: %v", err)
return fmt.Errorf("exporting state: %w", err)
}

appState := exported.AppState
Expand Down Expand Up @@ -116,7 +116,7 @@ func InspectCmd(appExporter types.AppExporter, appCreator types.AppCreator, defa
dataDir := filepath.Join(config.RootDir, "data")
directories, err := os.ReadDir(dataDir)
if err != nil {
return fmt.Errorf("Error reading directory: %v", err)
return fmt.Errorf("reading directory: %w", err)
}

for _, dir := range directories {
Expand Down
7 changes: 4 additions & 3 deletions cmd/dymd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"os"

"github.com/cosmos/cosmos-sdk/server"
Expand All @@ -13,10 +14,10 @@ import (
func main() {
rootCmd, _ := cmd.NewRootCmd()
if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil {
switch e := err.(type) {
case server.ErrorCode:
var e server.ErrorCode
switch {
case errors.As(err, &e):
os.Exit(e.Code)

default:
os.Exit(1)
}
Expand Down
6 changes: 3 additions & 3 deletions x/delayedack/eibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func (im IBCMiddleware) eIBCDemandOrderHandler(ctx sdk.Context, rollappPacket co

eibcDemandOrder, err := im.createDemandOrderFromIBCPacket(data, &rollappPacket, *packetMetaData.EIBC)
if err != nil {
return fmt.Errorf("create eibc demand order: %s", err)
return fmt.Errorf("create eibc demand order: %w", err)
}

err = im.keeper.SetDemandOrder(ctx, eibcDemandOrder)
if err != nil {
return fmt.Errorf("set eibc demand order: %s", err)
return fmt.Errorf("set eibc demand order: %w", err)
}
return nil
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (im IBCMiddleware) createDemandOrderFromIBCPacket(fungibleTokenPacketData t

order := eibctypes.NewDemandOrder(*rollappPacket, demandOrderPrice, fee, demandOrderDenom, demandOrderRecipient)
if err := order.Validate(); err != nil {
return nil, fmt.Errorf("validate eibc data: %s", err)
return nil, fmt.Errorf("validate eibc data: %w", err)
}
return order, nil
}
Expand Down

0 comments on commit 3ddff28

Please sign in to comment.