From c2b48bff064cf6f96eb0248056d44d16858f9de9 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 20 May 2024 03:33:03 +0800 Subject: [PATCH 1/9] lint --- ignite/cmd/plugin_test.go | 2 +- ignite/services/chain/init.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ignite/cmd/plugin_test.go b/ignite/cmd/plugin_test.go index 7513e016d5..167c89c498 100644 --- a/ignite/cmd/plugin_test.go +++ b/ignite/cmd/plugin_test.go @@ -86,7 +86,7 @@ func TestLinkPluginCmds(t *testing.T) { ) // helper to assert pluginInterface.Execute() calls - expectExecute := func(t *testing.T, ctx context.Context, p *mocks.PluginInterface, cmd *plugin.Command) { + expectExecute := func(t *testing.T, _ context.Context, p *mocks.PluginInterface, cmd *plugin.Command) { t.Helper() p.EXPECT(). Execute( diff --git a/ignite/services/chain/init.go b/ignite/services/chain/init.go index 863b58c6b0..f91c12347d 100644 --- a/ignite/services/chain/init.go +++ b/ignite/services/chain/init.go @@ -229,10 +229,6 @@ func (c *Chain) IsInitialized() (bool, error) { if _, err := os.Stat(gentxDir); os.IsNotExist(err) { return false, nil } - if err != nil { - // Return error on other error - return false, err - } return true, nil } From 6a6617f5360e44f55bf2cddcfb30d6861b061a31 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 20 May 2024 03:38:22 +0800 Subject: [PATCH 2/9] errcheck --- .golangci.yml | 8 +++----- ignite/cmd/completion.go | 21 +++++++++++++++------ ignite/internal/tools/gen-cli-docs/main.go | 4 +++- ignite/pkg/cosmosgen/cosmosgen.go | 7 ++++++- ignite/pkg/gomodule/gomodule.go | 3 +-- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index dd076db8ad..b0bbf830e4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,9 +1,5 @@ run: tests: false - skip-dirs: - - ignite/ui -# # timeout for analysis, e.g. 30s, 5m, default is 1m -# timeout: 5m linters: disable-all: true @@ -13,7 +9,7 @@ linters: - depguard - dogsled - dupword - # - errcheck + - errcheck - errchkjson - errorlint - exhaustive @@ -61,5 +57,7 @@ linters-settings: desc: Should be replaced by '"github.com/ignite/cli/ignite/pkg/errors"' issues: + exclude-dirs: + - ignite/ui max-issues-per-linter: 0 max-same-issues: 0 diff --git a/ignite/cmd/completion.go b/ignite/cmd/completion.go index 385a36ff1d..8edb10c51d 100644 --- a/ignite/cmd/completion.go +++ b/ignite/cmd/completion.go @@ -1,6 +1,7 @@ package ignitecmd import ( + "fmt" "os" "github.com/spf13/cobra" @@ -13,20 +14,28 @@ func NewCompletionCmd() *cobra.Command { Short: "Generates shell completion script.", Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { - cmd.Help() + if err := cmd.Help(); err != nil { + fmt.Fprintln(os.Stderr, "Error displaying help:", err) + os.Exit(1) + } os.Exit(0) } + var err error switch args[0] { case "bash": - cmd.Root().GenBashCompletion(os.Stdout) + err = cmd.Root().GenBashCompletion(os.Stdout) case "zsh": - cmd.Root().GenZshCompletion(os.Stdout) + err = cmd.Root().GenZshCompletion(os.Stdout) case "fish": - cmd.Root().GenFishCompletion(os.Stdout, true) + err = cmd.Root().GenFishCompletion(os.Stdout, true) case "powershell": - cmd.Root().GenPowerShellCompletion(os.Stdout) + err = cmd.Root().GenPowerShellCompletion(os.Stdout) default: - cmd.Help() + err = cmd.Help() + } + if err != nil { + fmt.Fprintln(os.Stderr, "Error generating completion script:", err) + os.Exit(1) } }, } diff --git a/ignite/internal/tools/gen-cli-docs/main.go b/ignite/internal/tools/gen-cli-docs/main.go index 0883b1736b..03382fe466 100644 --- a/ignite/internal/tools/gen-cli-docs/main.go +++ b/ignite/internal/tools/gen-cli-docs/main.go @@ -72,7 +72,9 @@ func run() error { } defer cleanUp() cmd.Flags().String(outFlag, ".", ".md file path to place Ignite CLI docs inside") - cmd.Flags().MarkHidden(outFlag) + if err := cmd.Flags().MarkHidden(outFlag); err != nil { + return err + } // Run ExecuteC so cobra adds the completion command. cmd, err = cmd.ExecuteC() diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index 4ea01a58f1..4f087987b9 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -2,6 +2,7 @@ package cosmosgen import ( "context" + "fmt" "os" "path/filepath" "strings" @@ -137,7 +138,11 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir return err } - defer b.Cleanup() + defer func() { + if err := b.Cleanup(); err != nil { + fmt.Println("Cleanup error:", err) + } + }() g := &generator{ buf: b, diff --git a/ignite/pkg/gomodule/gomodule.go b/ignite/pkg/gomodule/gomodule.go index 6a4aec5273..cdbadb2ba9 100644 --- a/ignite/pkg/gomodule/gomodule.go +++ b/ignite/pkg/gomodule/gomodule.go @@ -188,11 +188,10 @@ func FindModule(ctx context.Context, rootDir, path string) (Module, error) { for dec.More() { var m Module - if dec.Decode(&m); err != nil { + if err := dec.Decode(&m); err != nil { if errors.Is(err, io.EOF) { break } - return Module{}, err } From acd2b4e2d5b2e2d1c0d70d0cae65589a6407668f Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 20 May 2024 03:45:23 +0800 Subject: [PATCH 3/9] check errors in interface_flag.go --- .../services/plugin/grpc/v1/interface_flag.go | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/ignite/services/plugin/grpc/v1/interface_flag.go b/ignite/services/plugin/grpc/v1/interface_flag.go index 8369d476c2..c3836f0ce4 100644 --- a/ignite/services/plugin/grpc/v1/interface_flag.go +++ b/ignite/services/plugin/grpc/v1/interface_flag.go @@ -42,7 +42,9 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error { } fs.BoolP(f.Name, f.Shorthand, v, f.Usage) - fs.Set(f.Name, f.Value) + if err := fs.Set(f.Name, f.Value); err != nil { + return err + } case Flag_TYPE_FLAG_INT: v, err := strconv.Atoi(f.DefaultValue) if err != nil { @@ -50,7 +52,9 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error { } fs.IntP(f.Name, f.Shorthand, v, f.Usage) - fs.Set(f.Name, f.Value) + if err := fs.Set(f.Name, f.Value); err != nil { + return err + } case Flag_TYPE_FLAG_UINT: v, err := strconv.ParseUint(f.DefaultValue, 10, 64) if err != nil { @@ -58,7 +62,9 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error { } fs.UintP(f.Name, f.Shorthand, uint(v), f.Usage) - fs.Set(f.Name, f.Value) + if err := fs.Set(f.Name, f.Value); err != nil { + return err + } case Flag_TYPE_FLAG_INT64: v, err := strconv.ParseInt(f.DefaultValue, 10, 64) if err != nil { @@ -66,7 +72,9 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error { } fs.Int64P(f.Name, f.Shorthand, v, f.Usage) - fs.Set(f.Name, f.Value) + if err := fs.Set(f.Name, f.Value); err != nil { + return err + } case Flag_TYPE_FLAG_UINT64: v, err := strconv.ParseUint(f.DefaultValue, 10, 64) if err != nil { @@ -74,14 +82,20 @@ func (f *Flag) exportToFlagSet(fs *pflag.FlagSet) error { } fs.Uint64P(f.Name, f.Shorthand, v, f.Usage) - fs.Set(f.Name, f.Value) + if err := fs.Set(f.Name, f.Value); err != nil { + return err + } case Flag_TYPE_FLAG_STRING_SLICE: s := strings.Trim(f.DefaultValue, "[]") fs.StringSliceP(f.Name, f.Shorthand, strings.Fields(s), f.Usage) - fs.Set(f.Name, strings.Trim(f.Value, "[]")) + if err := fs.Set(f.Name, strings.Trim(f.Value, "[]")); err != nil { + return err + } case Flag_TYPE_FLAG_STRING_UNSPECIFIED: fs.StringP(f.Name, f.Shorthand, f.DefaultValue, f.Usage) - fs.Set(f.Name, f.Value) + if err := fs.Set(f.Name, f.Value); err != nil { + return err + } } return nil } From e75bbf5993a57d299038ff74ea07bf88d5b02cd2 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 20 May 2024 04:25:56 +0800 Subject: [PATCH 4/9] set value in tests --- .golangci.yml | 4 ---- ignite/internal/plugin/testdata/execute_fail/go.mod | 7 +++---- ignite/internal/plugin/testdata/execute_ok/go.mod | 7 +++---- ignite/services/plugin/grpc/v1/types_command_test.go | 2 ++ 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b0bbf830e4..7be8f406eb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -18,12 +18,10 @@ linters: - godot - gofumpt - revive - # - gosec - gosimple - govet - grouper - ineffassign - # - interfacer - misspell - nakedret - nolintlint @@ -39,8 +37,6 @@ linters: - unparam - misspell - forbidigo - # - wrapcheck - # - wsl linters-settings: forbidigo: diff --git a/ignite/internal/plugin/testdata/execute_fail/go.mod b/ignite/internal/plugin/testdata/execute_fail/go.mod index 1488336a18..70754ecb2c 100644 --- a/ignite/internal/plugin/testdata/execute_fail/go.mod +++ b/ignite/internal/plugin/testdata/execute_fail/go.mod @@ -1,8 +1,8 @@ module execute_fail -go 1.21.1 +go 1.22 -toolchain go1.21.5 +toolchain go1.22.3 require ( github.com/hashicorp/go-plugin v1.6.0 @@ -82,7 +82,6 @@ require ( github.com/xanzy/ssh-agent v0.3.3 // indirect go.etcd.io/bbolt v1.3.9 // indirect golang.org/x/crypto v0.22.0 // indirect - golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sync v0.7.0 // indirect @@ -95,5 +94,5 @@ require ( google.golang.org/grpc v1.63.2 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/ignite/internal/plugin/testdata/execute_ok/go.mod b/ignite/internal/plugin/testdata/execute_ok/go.mod index 484f6a45cb..5df5dceccd 100644 --- a/ignite/internal/plugin/testdata/execute_ok/go.mod +++ b/ignite/internal/plugin/testdata/execute_ok/go.mod @@ -1,8 +1,8 @@ module execute_ok -go 1.21.1 +go 1.22 -toolchain go1.21.5 +toolchain go1.22.3 require ( github.com/hashicorp/go-plugin v1.6.0 @@ -82,7 +82,6 @@ require ( github.com/xanzy/ssh-agent v0.3.3 // indirect go.etcd.io/bbolt v1.3.9 // indirect golang.org/x/crypto v0.22.0 // indirect - golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sync v0.7.0 // indirect @@ -95,5 +94,5 @@ require ( google.golang.org/grpc v1.63.2 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/ignite/services/plugin/grpc/v1/types_command_test.go b/ignite/services/plugin/grpc/v1/types_command_test.go index 0547684a35..343a0d0f46 100644 --- a/ignite/services/plugin/grpc/v1/types_command_test.go +++ b/ignite/services/plugin/grpc/v1/types_command_test.go @@ -149,6 +149,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "b", Usage: "bool usage", DefaultValue: "false", + Value: "true", Type: v1.Flag_TYPE_FLAG_BOOL, }, { @@ -247,6 +248,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) { Shorthand: "b", Usage: "bool usage", DefaultValue: "false", + Value: "true", Type: v1.Flag_TYPE_FLAG_BOOL, Persistent: true, }, From 71fece90c76363e6824590a99cf5be3b709f9fd0 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 20 May 2024 04:31:17 +0800 Subject: [PATCH 5/9] fix test --- ignite/services/plugin/grpc/v1/types_command_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ignite/services/plugin/grpc/v1/types_command_test.go b/ignite/services/plugin/grpc/v1/types_command_test.go index 343a0d0f46..8958006ac7 100644 --- a/ignite/services/plugin/grpc/v1/types_command_test.go +++ b/ignite/services/plugin/grpc/v1/types_command_test.go @@ -157,6 +157,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "i", Usage: "int usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_INT, }, { @@ -164,6 +165,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "u", Usage: "uint usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_UINT, }, { @@ -171,6 +173,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "j", Usage: "int64 usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_INT64, }, { @@ -178,6 +181,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "k", Usage: "uint64 usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_UINT64, }, { @@ -185,6 +189,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "s", Usage: "string usage", DefaultValue: "", + Value: "hello", Type: v1.Flag_TYPE_FLAG_STRING_UNSPECIFIED, }, { @@ -192,6 +197,7 @@ func TestExecutedCommandNewFlags(t *testing.T) { Shorthand: "l", Usage: "string slice usage", DefaultValue: "[]", + Value: "[]", Type: v1.Flag_TYPE_FLAG_STRING_SLICE, }, { @@ -257,6 +263,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) { Shorthand: "i", Usage: "int usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_INT, Persistent: true, }, @@ -265,6 +272,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) { Shorthand: "u", Usage: "uint usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_UINT, Persistent: true, }, @@ -273,6 +281,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) { Shorthand: "j", Usage: "int64 usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_INT64, Persistent: true, }, @@ -281,6 +290,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) { Shorthand: "k", Usage: "uint64 usage", DefaultValue: "0", + Value: "42", Type: v1.Flag_TYPE_FLAG_UINT64, Persistent: true, }, @@ -289,6 +299,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) { Shorthand: "s", Usage: "string usage", DefaultValue: "", + Value: "hello", Type: v1.Flag_TYPE_FLAG_STRING_UNSPECIFIED, Persistent: true, }, @@ -297,6 +308,7 @@ func TestExecutedCommandNewPersistentFlags(t *testing.T) { Shorthand: "l", Usage: "string slice usage", DefaultValue: "[]", + Value: "[]", Type: v1.Flag_TYPE_FLAG_STRING_SLICE, Persistent: true, }, From 182a724bf7c143c728d0b65e72d877e704de1c3c Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 20 May 2024 04:44:20 +0800 Subject: [PATCH 6/9] always provide a value when testing flags --- ignite/cmd/plugin_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/cmd/plugin_test.go b/ignite/cmd/plugin_test.go index 167c89c498..d4cf70fede 100644 --- a/ignite/cmd/plugin_test.go +++ b/ignite/cmd/plugin_test.go @@ -80,7 +80,7 @@ func TestLinkPluginCmds(t *testing.T) { Use: "flaggy", Flags: []*plugin.Flag{ {Name: "flag1", Type: plugin.FlagTypeString}, - {Name: "flag2", Type: plugin.FlagTypeInt, DefaultValue: "0"}, + {Name: "flag2", Type: plugin.FlagTypeInt, DefaultValue: "0", Value: "0"}, }, } ) From a9bfcc5cb82e5db5e5ed6e80b9722d1313f61244 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 20 May 2024 15:48:56 +0800 Subject: [PATCH 7/9] add a comment to trigger ci --- integration/cosmosgen/bank_module_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integration/cosmosgen/bank_module_test.go b/integration/cosmosgen/bank_module_test.go index 435e27a5eb..774f1c8822 100644 --- a/integration/cosmosgen/bank_module_test.go +++ b/integration/cosmosgen/bank_module_test.go @@ -14,6 +14,7 @@ import ( envtest "github.com/ignite/cli/v29/integration" ) +// TestBankModule tests the bank module by creating accounts, transferring tokens between them, and querying the account balances. func TestBankModule(t *testing.T) { t.Skip() From aaf0a86e3347a68095176609c7dedfe86d4a4e23 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 20 May 2024 16:03:32 +0800 Subject: [PATCH 8/9] changelog --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index cf8cca8401..89f8badee5 100644 --- a/changelog.md +++ b/changelog.md @@ -21,6 +21,8 @@ ### Changes + +- [#4162](https://github.com/ignite/cli/pull/4162) Enable errcheck linter and fix a bug in the way we test flags - [#4157](https://github.com/ignite/cli/pull/4157) Upgrade golang to 1.22 - [#4094](https://github.com/ignite/cli/pull/4094) Scaffolding a multi-index map using `ignite s map foo bar baz --index foobar,foobaz` is no longer supported. Use one index instead of use `collections.IndexedMap`. - [#4058](https://github.com/ignite/cli/pull/4058) Simplify scaffolded modules by including `ValidateBasic()` logic in message handler. From 5978cf2a1ebc641db0593e400dc0569d3359c8e7 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Thu, 13 Jun 2024 16:48:31 +0300 Subject: [PATCH 9/9] fix removed errors --- ignite/pkg/cosmosgen/cosmosgen.go | 8 -------- ignite/services/chain/init.go | 2 ++ integration/plugin/testdata/example-plugin/go.mod | 4 ++-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index 4a256d52f4..6235d736d9 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -2,7 +2,6 @@ package cosmosgen import ( "context" - "fmt" "os" "path/filepath" "strings" @@ -129,13 +128,6 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir return err } - defer func() { - if err := b.Cleanup(); err != nil { - fmt.Println("Cleanup error:", err) - } - }() - - g := &generator{ buf: b, appPath: appPath, diff --git a/ignite/services/chain/init.go b/ignite/services/chain/init.go index f91c12347d..bc25b0aba9 100644 --- a/ignite/services/chain/init.go +++ b/ignite/services/chain/init.go @@ -228,6 +228,8 @@ func (c *Chain) IsInitialized() (bool, error) { if _, err := os.Stat(gentxDir); os.IsNotExist(err) { return false, nil + } else if err != nil { + return false, err } return true, nil diff --git a/integration/plugin/testdata/example-plugin/go.mod b/integration/plugin/testdata/example-plugin/go.mod index fa81cbccaf..c94900f976 100644 --- a/integration/plugin/testdata/example-plugin/go.mod +++ b/integration/plugin/testdata/example-plugin/go.mod @@ -1,8 +1,8 @@ module example-plugin -go 1.21.1 +go 1.22 -toolchain go1.21.4 +toolchain go1.22.3 require ( github.com/hashicorp/go-plugin v1.6.0