From bc03a0edfc6bf0d16153bc019a67a1ff410c8a8e Mon Sep 17 00:00:00 2001 From: huofei <68298506@qq.com> Date: Thu, 21 Jul 2022 13:56:56 +0800 Subject: [PATCH] [ioctl] fix Errors unhandled (#3567) * fix error unhandle * fix pkg error unhandled * fix error unhandled in tools * fix compress close handle * return error for AskToConfirm Co-authored-by: Raullen Chai --- ioctl/client.go | 10 ++++++---- ioctl/client_test.go | 5 +++-- ioctl/cmd/account/accountcreateadd.go | 4 +++- ioctl/cmd/account/accountdelete.go | 4 +++- ioctl/cmd/action/action.go | 4 +++- ioctl/cmd/action/xrc20.go | 4 +++- ioctl/cmd/contract/contractshare.go | 10 +++++++--- ioctl/cmd/hdwallet/hdwalletdelete.go | 4 +++- ioctl/cmd/node/nodedelegate.go | 4 +++- ioctl/config/configsetget.go | 4 +++- ioctl/flag/flag.go | 6 +++++- ioctl/newcmd/account/accountcreateadd.go | 6 +++++- ioctl/newcmd/account/accountcreateadd_test.go | 4 ++-- ioctl/newcmd/account/accountdelete.go | 10 +++++++--- ioctl/newcmd/account/accountdelete_test.go | 6 +++--- ioctl/newcmd/action/action.go | 8 ++++++-- ioctl/newcmd/hdwallet/hdwalletdelete.go | 7 ++++++- ioctl/newcmd/hdwallet/hdwalletdelete_test.go | 4 ++-- ioctl/newcmd/update/update.go | 8 ++++++-- ioctl/newcmd/update/update_test.go | 4 ++-- pkg/compress/compress.go | 13 ++++++++----- state/account.go | 2 +- test/mock/mock_ioctlclient/mock_ioctlclient.go | 5 +++-- tools/actioninjector.v2/internal/cmd/inject.go | 8 +++++--- tools/iomigrater/cmds/migrate-db.go | 14 +++++++++----- 25 files changed, 107 insertions(+), 51 deletions(-) diff --git a/ioctl/client.go b/ioctl/client.go index ed85ab6da8..64560b903d 100644 --- a/ioctl/client.go +++ b/ioctl/client.go @@ -53,7 +53,7 @@ type ( // SelectTranslation select a translation based on UILanguage SelectTranslation(map[config.Language]string) (string, config.Language) // AskToConfirm asks user to confirm from terminal, true to continue - AskToConfirm(string) bool + AskToConfirm(string) (bool, error) // ReadSecret reads password from terminal ReadSecret() (string, error) // Execute a bash command @@ -173,12 +173,14 @@ func (c *client) SetInsecureWithFlag(cb func(*bool, string, bool, string)) { cb(&c.insecure, "insecure", !c.cfg.SecureConnect, usage) } -func (c *client) AskToConfirm(info string) bool { +func (c *client) AskToConfirm(info string) (bool, error) { message := ConfirmationMessage{Info: info, Options: []string{"yes"}} fmt.Println(message.String()) var confirm string - fmt.Scanf("%s", &confirm) - return strings.EqualFold(confirm, "yes") + if _, err := fmt.Scanf("%s", &confirm); err != nil { + return false, err + } + return strings.EqualFold(confirm, "yes"), nil } func (c *client) SelectTranslation(trls map[config.Language]string) (string, config.Language) { diff --git a/ioctl/client_test.go b/ioctl/client_test.go index 27891534f3..a72da30fa7 100644 --- a/ioctl/client_test.go +++ b/ioctl/client_test.go @@ -38,9 +38,10 @@ func TestAskToConfirm(t *testing.T) { r := require.New(t) c := NewClient(config.Config{}, "") defer c.Stop(context.Background()) - blang := c.AskToConfirm("test") + confirmed, err := c.AskToConfirm("test") // no input - r.False(blang) + r.Equal("EOF", err.Error()) + r.False(confirmed) } func TestAPIServiceClient(t *testing.T) { diff --git a/ioctl/cmd/account/accountcreateadd.go b/ioctl/cmd/account/accountcreateadd.go index 89e3d86a1c..07cb54aeea 100644 --- a/ioctl/cmd/account/accountcreateadd.go +++ b/ioctl/cmd/account/accountcreateadd.go @@ -56,7 +56,9 @@ func accountCreateAdd(args []string) error { "but bind the alias to the new one.\nWould you like to continue?\n", alias, addr) message := output.ConfirmationMessage{Info: info, Options: []string{"yes"}} fmt.Println(message.String()) - fmt.Scanf("%s", &confirm) + if _, err := fmt.Scanf("%s", &confirm); err != nil { + return output.NewError(output.InputError, "failed to input yes", err) + } if !strings.EqualFold(confirm, "yes") { output.PrintResult("quit") return nil diff --git a/ioctl/cmd/account/accountdelete.go b/ioctl/cmd/account/accountdelete.go index 502f8f1824..aea60ef8ae 100644 --- a/ioctl/cmd/account/accountdelete.go +++ b/ioctl/cmd/account/accountdelete.go @@ -91,7 +91,9 @@ func accountDelete(arg string) error { "Type 'YES' to continue, quit for anything else.") message := output.ConfirmationMessage{Info: info, Options: []string{"yes"}} fmt.Println(message.String()) - fmt.Scanf("%s", &confirm) + if _, err := fmt.Scanf("%s", &confirm); err != nil { + return output.NewError(output.InputError, "failed to input yes", err) + } if !strings.EqualFold(confirm, "yes") { output.PrintResult("quit") return nil diff --git a/ioctl/cmd/action/action.go b/ioctl/cmd/action/action.go index b735a04541..b944174f84 100644 --- a/ioctl/cmd/action/action.go +++ b/ioctl/cmd/action/action.go @@ -295,7 +295,9 @@ func SendAction(elp action.Envelope, signer string) error { message := output.ConfirmationMessage{Info: info, Options: []string{"yes"}} fmt.Println(message.String()) - fmt.Scanf("%s", &confirm) + if _, err := fmt.Scanf("%s", &confirm); err != nil { + return output.NewError(output.InputError, "failed to input yes", err) + } if !strings.EqualFold(confirm, "yes") { output.PrintResult("quit") return nil diff --git a/ioctl/cmd/action/xrc20.go b/ioctl/cmd/action/xrc20.go index 1718d73e15..d857bdf84f 100644 --- a/ioctl/cmd/action/xrc20.go +++ b/ioctl/cmd/action/xrc20.go @@ -83,7 +83,9 @@ func init() { config.ReadConfig.Endpoint, config.TranslateInLang(_flagXrc20EndPointUsages, config.UILanguage)) Xrc20Cmd.PersistentFlags().BoolVar(&config.Insecure, "insecure", config.Insecure, config.TranslateInLang(_flagXrc20InsecureUsages, config.UILanguage)) - cobra.MarkFlagRequired(Xrc20Cmd.PersistentFlags(), "contract-address") + if err := cobra.MarkFlagRequired(Xrc20Cmd.PersistentFlags(), "contract-address"); err != nil { + fmt.Printf("failed to mark flag: %v\n", err) + } } func parseAmount(contract address.Address, amount string) (*big.Int, error) { diff --git a/ioctl/cmd/contract/contractshare.go b/ioctl/cmd/contract/contractshare.go index cb89582290..b1fc5d4ab0 100644 --- a/ioctl/cmd/contract/contractshare.go +++ b/ioctl/cmd/contract/contractshare.go @@ -102,7 +102,9 @@ func isReadOnly(path string) bool { } readOnly = true } - file.Close() + if err = file.Close(); err != nil { + log.Printf("fialed to close file: %v", err) + } return readOnly } @@ -140,7 +142,7 @@ func share(args []string) error { return output.NewError(output.FlagError, "failed to get IoTeX ide url instance", nil) } - filepath.Walk(_givenPath, func(path string, info os.FileInfo, err error) error { + if err := filepath.Walk(_givenPath, func(path string, info os.FileInfo, err error) error { if !isDir(path) { relPath, err := filepath.Rel(_givenPath, path) if err != nil { @@ -152,7 +154,9 @@ func share(args []string) error { } } return nil - }) + }); err != nil { + return output.NewError(output.ReadFileError, "failed to walk directory", err) + } log.Printf("Listening on 127.0.0.1:65520, Please open your IDE ( %s ) to connect to local files", _iotexIDE) diff --git a/ioctl/cmd/hdwallet/hdwalletdelete.go b/ioctl/cmd/hdwallet/hdwalletdelete.go index 260c253798..b98c283078 100644 --- a/ioctl/cmd/hdwallet/hdwalletdelete.go +++ b/ioctl/cmd/hdwallet/hdwalletdelete.go @@ -44,7 +44,9 @@ func hdwalletDelete() error { "Type 'YES' to continue, quit for anything else.") message := output.ConfirmationMessage{Info: info, Options: []string{"yes"}} fmt.Println(message.String()) - fmt.Scanf("%s", &confirm) + if _, err := fmt.Scanf("%s", &confirm); err != nil { + return output.NewError(output.InputError, "failed to input yes", err) + } if !strings.EqualFold(confirm, "yes") { output.PrintResult("quit") return nil diff --git a/ioctl/cmd/node/nodedelegate.go b/ioctl/cmd/node/nodedelegate.go index bff2272350..c6ca3a3f03 100644 --- a/ioctl/cmd/node/nodedelegate.go +++ b/ioctl/cmd/node/nodedelegate.go @@ -253,7 +253,9 @@ func delegatesV2(pb *vote.ProbationList, epochMeta *iotexapi.GetEpochMetaRespons ProbatedStatus: isProbated, }) } - fillMessage(cli, message, aliases, isActive, pb) + if err = fillMessage(cli, message, aliases, isActive, pb); err != nil { + return err + } return sortAndPrint(message) } diff --git a/ioctl/config/configsetget.go b/ioctl/config/configsetget.go index 5da1d8cc3c..3ae20b2ad4 100644 --- a/ioctl/config/configsetget.go +++ b/ioctl/config/configsetget.go @@ -239,7 +239,9 @@ func set(args []string) error { case args[1] == "custom": output.PrintQuery(`Please enter a custom link below:("Example: iotexscan.io/action/")`) var link string - fmt.Scanln(&link) + if _, err := fmt.Scanln(&link); err != nil { + return output.NewError(output.InputError, "failed to input link", err) + } match, err := regexp.MatchString(_urlPattern, link) if err != nil { return output.NewError(output.UndefinedError, "failed to validate link", nil) diff --git a/ioctl/flag/flag.go b/ioctl/flag/flag.go index 6069c74059..01610291e9 100644 --- a/ioctl/flag/flag.go +++ b/ioctl/flag/flag.go @@ -7,6 +7,8 @@ package flag import ( + "fmt" + "github.com/spf13/cobra" "github.com/iotexproject/iotex-core/ioctl/config" @@ -57,7 +59,9 @@ type ( ) func (f *flagBase) MarkFlagRequired(cmd *cobra.Command) { - cmd.MarkFlagRequired(f.label) + if err := cmd.MarkFlagRequired(f.label); err != nil { + fmt.Printf("failed to mark flag %s: %v\n", f.label, err) + } } func (f *flagBase) Label() string { diff --git a/ioctl/newcmd/account/accountcreateadd.go b/ioctl/newcmd/account/accountcreateadd.go index 57762732d9..4737e16b33 100644 --- a/ioctl/newcmd/account/accountcreateadd.go +++ b/ioctl/newcmd/account/accountcreateadd.go @@ -71,7 +71,11 @@ func NewAccountCreateAdd(client ioctl.Client) *cobra.Command { } if addr, ok := client.Config().Aliases[args[0]]; ok { - if !client.AskToConfirm(fmt.Sprintf(_aliasHasAlreadyUsed, args[0], addr)) { + confirmed, err := client.AskToConfirm(fmt.Sprintf(_aliasHasAlreadyUsed, args[0], addr)) + if err != nil { + return errors.Wrap(err, "failed to ask confirm") + } + if !confirmed { cmd.Println(infoQuit) return nil } diff --git a/ioctl/newcmd/account/accountcreateadd_test.go b/ioctl/newcmd/account/accountcreateadd_test.go index 7d6c8bc679..ab6be5f8be 100644 --- a/ioctl/newcmd/account/accountcreateadd_test.go +++ b/ioctl/newcmd/account/accountcreateadd_test.go @@ -29,7 +29,7 @@ func TestNewAccountCreateAdd(t *testing.T) { require.NoError(err) client.EXPECT().ReadSecret().Return(pwd, nil).Times(4) - client.EXPECT().AskToConfirm(gomock.Any()).Return(true).Times(2) + client.EXPECT().AskToConfirm(gomock.Any()).Return(true, nil).Times(2) client.EXPECT().Config().Return(config.Config{ Wallet: testWallet, Aliases: map[string]string{ @@ -57,7 +57,7 @@ func TestNewAccountCreateAdd(t *testing.T) { }) t.Run("failed to confirm", func(t *testing.T) { - client.EXPECT().AskToConfirm(gomock.Any()).Return(false) + client.EXPECT().AskToConfirm(gomock.Any()).Return(false, nil) cmd := NewAccountCreateAdd(client) _, err := util.ExecuteCmd(cmd, "aaa") diff --git a/ioctl/newcmd/account/accountdelete.go b/ioctl/newcmd/account/accountdelete.go index 2c5249dfc4..f79cf11160 100644 --- a/ioctl/newcmd/account/accountdelete.go +++ b/ioctl/newcmd/account/accountdelete.go @@ -120,14 +120,18 @@ func NewAccountDelete(client ioctl.Client) *cobra.Command { if _, err = os.Stat(filePath); err != nil { return errors.Wrapf(err, _failToFindAccount, addr) } - if !client.AskToConfirm(_infoWarn) { + confirmed, err := client.AskToConfirm(_infoWarn) + if err != nil { + return errors.Wrap(err, "failed to ask confirm") + } + if !confirmed { cmd.Println(_infoQuit) return nil } - if err := os.Remove(filePath); err != nil { + if err = os.Remove(filePath); err != nil { return errors.Wrap(err, _failToRemoveKeystoreFile) } - if err := client.DeleteAlias(client.AliasMap()[addr]); err != nil { + if err = client.DeleteAlias(client.AliasMap()[addr]); err != nil { return errors.Wrap(err, _failToWriteToConfigFile) } cmd.Println(fmt.Sprintf(_resultSuccess, addr)) diff --git a/ioctl/newcmd/account/accountdelete_test.go b/ioctl/newcmd/account/accountdelete_test.go index c25e8a448b..923a3ababa 100644 --- a/ioctl/newcmd/account/accountdelete_test.go +++ b/ioctl/newcmd/account/accountdelete_test.go @@ -44,12 +44,12 @@ func TestNewAccountDelete(t *testing.T) { "io1uwnr55vqmhf3xeg5phgurlyl702af6eju542s1": "ccc", }) - client.EXPECT().AskToConfirm(gomock.Any()).Return(false) + client.EXPECT().AskToConfirm(gomock.Any()).Return(false, nil) cmd := NewAccountDelete(client) _, err := util.ExecuteCmd(cmd) require.NoError(err) - client.EXPECT().AskToConfirm(gomock.Any()).Return(true) + client.EXPECT().AskToConfirm(gomock.Any()).Return(true, nil) client.EXPECT().DeleteAlias("aaa").Return(nil) cmd = NewAccountDelete(client) result, err := util.ExecuteCmd(cmd) @@ -82,7 +82,7 @@ func TestNewAccountDelete(t *testing.T) { crypto.WritePrivateKeyToPem(pemFilePath, priKey2.(*crypto.P256sm2PrvKey), "test") client.EXPECT().AddressWithDefaultIfNotExist(gomock.Any()).Return(addr2.String(), nil) - client.EXPECT().AskToConfirm(gomock.Any()).Return(true) + client.EXPECT().AskToConfirm(gomock.Any()).Return(true, nil) client.EXPECT().DeleteAlias("aaa").Return(nil) cmd := NewAccountDelete(client) result, err := util.ExecuteCmd(cmd) diff --git a/ioctl/newcmd/action/action.go b/ioctl/newcmd/action/action.go index 802aa14752..eb94bd16cb 100644 --- a/ioctl/newcmd/action/action.go +++ b/ioctl/newcmd/action/action.go @@ -396,10 +396,14 @@ func SendAction(client ioctl.Client, cmd *cobra.Command, elp action.Envelope, si if !getAssumeYesFlagValue(cmd) { infoWarn := selectTranslation(client, _infoWarn) infoQuit := selectTranslation(client, _infoQuit) - if !client.AskToConfirm(infoWarn) { + confirmed, err := client.AskToConfirm(infoWarn) + if err != nil { + return errors.Wrap(err, "failed to ask confirm") + } + if !confirmed { cmd.Println(infoQuit) + return nil } - return nil } return SendRaw(client, cmd, selp) diff --git a/ioctl/newcmd/hdwallet/hdwalletdelete.go b/ioctl/newcmd/hdwallet/hdwalletdelete.go index 7eeead1676..0b5c659673 100644 --- a/ioctl/newcmd/hdwallet/hdwalletdelete.go +++ b/ioctl/newcmd/hdwallet/hdwalletdelete.go @@ -9,6 +9,7 @@ package hdwallet import ( "fmt" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/iotexproject/iotex-core/ioctl" @@ -36,7 +37,11 @@ func NewHdwalletDeleteCmd(client ioctl.Client) *cobra.Command { info := fmt.Sprintf("** This is an irreversible action!\n" + "Once an hdwallet is deleted, all the assets under this hdwallet may be lost!\n" + "Type 'YES' to continue, quit for anything else.") - if !client.AskToConfirm(info) { + confirmed, err := client.AskToConfirm(info) + if err != nil { + return errors.Wrap(err, "failed to ask confirm") + } + if !confirmed { cmd.Println("quit") return nil } diff --git a/ioctl/newcmd/hdwallet/hdwalletdelete_test.go b/ioctl/newcmd/hdwallet/hdwalletdelete_test.go index a51131894b..b0df5819af 100644 --- a/ioctl/newcmd/hdwallet/hdwalletdelete_test.go +++ b/ioctl/newcmd/hdwallet/hdwalletdelete_test.go @@ -25,7 +25,7 @@ func TestNewHdwalletDeleteCmd(t *testing.T) { client.EXPECT().SelectTranslation(gomock.Any()).Return("mockTranslationString", config.English).Times(4) t.Run("delete hdwallet", func(t *testing.T) { - client.EXPECT().AskToConfirm(gomock.Any()).Return(true) + client.EXPECT().AskToConfirm(gomock.Any()).Return(true, nil) client.EXPECT().RemoveHdWalletConfigFile().Return(nil) cmd := NewHdwalletDeleteCmd(client) @@ -35,7 +35,7 @@ func TestNewHdwalletDeleteCmd(t *testing.T) { }) t.Run("quit hdwallet delete command", func(t *testing.T) { - client.EXPECT().AskToConfirm(gomock.Any()).Return(false) + client.EXPECT().AskToConfirm(gomock.Any()).Return(false, nil) cmd := NewHdwalletDeleteCmd(client) result, err := util.ExecuteCmd(cmd) diff --git a/ioctl/newcmd/update/update.go b/ioctl/newcmd/update/update.go index 7f4127b117..b20767b2a9 100644 --- a/ioctl/newcmd/update/update.go +++ b/ioctl/newcmd/update/update.go @@ -86,13 +86,17 @@ func NewUpdateCmd(c ioctl.Client) *cobra.Command { return errors.New(fmt.Sprintf(invalidVersionType, versionType)) } - if !c.AskToConfirm(_infoWarn) { + confirmed, err := c.AskToConfirm(_infoWarn) + if err != nil { + return errors.Wrap(err, "failed to ask confirm") + } + if !confirmed { cmd.Println(_infoQuit) return nil } cmd.Printf(info, versionType) - if err := c.Execute(cmdString); err != nil { + if err = c.Execute(cmdString); err != nil { return errors.Wrap(err, fail) } cmd.Println(success) diff --git a/ioctl/newcmd/update/update_test.go b/ioctl/newcmd/update/update_test.go index 223171b76e..ed5dc4ecc1 100644 --- a/ioctl/newcmd/update/update_test.go +++ b/ioctl/newcmd/update/update_test.go @@ -26,7 +26,7 @@ func TestNewUpdateCmd(t *testing.T) { expectedValue := "ioctl is up-to-date now." client.EXPECT().SelectTranslation(gomock.Any()).Return(expectedValue, config.English).Times(18) - client.EXPECT().AskToConfirm(gomock.Any()).Return(true).Times(2) + client.EXPECT().AskToConfirm(gomock.Any()).Return(true, nil).Times(2) client.EXPECT().Execute(gomock.Any()).Return(nil).Times(2) t.Run("update cli with stable", func(t *testing.T) { @@ -47,7 +47,7 @@ func TestNewUpdateCmd(t *testing.T) { expectedError := errors.New("failed to execute bash command") client.EXPECT().SelectTranslation(gomock.Any()).Return("mockTranslationResult", config.English).Times(9) - client.EXPECT().AskToConfirm(gomock.Any()).Return(true).Times(1) + client.EXPECT().AskToConfirm(gomock.Any()).Return(true, nil).Times(1) client.EXPECT().Execute(gomock.Any()).Return(expectedError).Times(1) cmd := NewUpdateCmd(client) diff --git a/pkg/compress/compress.go b/pkg/compress/compress.go index e4d4b276a3..bdebd2d1a0 100644 --- a/pkg/compress/compress.go +++ b/pkg/compress/compress.go @@ -61,12 +61,13 @@ func CompGzip(data []byte) ([]byte, error) { if err != nil { return nil, err } - _, err = w.Write(data) - if err != nil { - w.Close() + if _, err = w.Write(data); err != nil { + err = w.Close() + return nil, err + } + if err = w.Close(); err != nil { return nil, err } - w.Close() output := bb.Bytes() return output, nil } @@ -77,7 +78,9 @@ func DecompGzip(data []byte) ([]byte, error) { if err != nil { return nil, err } - r.Close() + if err = r.Close(); err != nil { + return nil, err + } return io.ReadAll(r) } diff --git a/state/account.go b/state/account.go index 8b128caea9..b6c8844dbf 100644 --- a/state/account.go +++ b/state/account.go @@ -102,7 +102,7 @@ func (st *Account) FromProto(acPb *accountpb.Account) { } else { balance, ok := new(big.Int).SetString(acPb.Balance, 10) if !ok { - errors.Errorf("invalid balance %s", acPb.Balance) + panic(errors.Errorf("invalid balance %s", acPb.Balance)) } st.Balance = balance } diff --git a/test/mock/mock_ioctlclient/mock_ioctlclient.go b/test/mock/mock_ioctlclient/mock_ioctlclient.go index e60fcf4ddd..dbfd5287b8 100644 --- a/test/mock/mock_ioctlclient/mock_ioctlclient.go +++ b/test/mock/mock_ioctlclient/mock_ioctlclient.go @@ -114,11 +114,12 @@ func (mr *MockClientMockRecorder) AliasMap() *gomock.Call { } // AskToConfirm mocks base method. -func (m *MockClient) AskToConfirm(arg0 string) bool { +func (m *MockClient) AskToConfirm(arg0 string) (bool, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AskToConfirm", arg0) ret0, _ := ret[0].(bool) - return ret0 + ret1, _ := ret[1].(error) + return ret0, ret1 } // AskToConfirm indicates an expected call of AskToConfirm. diff --git a/tools/actioninjector.v2/internal/cmd/inject.go b/tools/actioninjector.v2/internal/cmd/inject.go index 145e861bfe..b017c4fd7d 100644 --- a/tools/actioninjector.v2/internal/cmd/inject.go +++ b/tools/actioninjector.v2/internal/cmd/inject.go @@ -23,6 +23,7 @@ import ( "github.com/cenkalti/backoff" "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/iotexproject/go-pkgs/cache/ttl" "github.com/iotexproject/go-pkgs/crypto" "github.com/iotexproject/go-pkgs/hash" "github.com/iotexproject/iotex-address/address" @@ -36,7 +37,6 @@ import ( "google.golang.org/grpc/credentials" yaml "gopkg.in/yaml.v2" - "github.com/iotexproject/go-pkgs/cache/ttl" "github.com/iotexproject/iotex-core/pkg/log" ) @@ -87,7 +87,9 @@ func newInjectionProcessor() (*injectProcessor, error) { api: api, nonces: nonceCache, } - p.randAccounts(injectCfg.randAccounts) + if err = p.randAccounts(injectCfg.randAccounts); err != nil { + return p, err + } if injectCfg.loadTokenAmount.BitLen() != 0 { if err := p.loadAccounts(injectCfg.configPath); err != nil { return p, err @@ -395,7 +397,7 @@ func inject(_ []string) string { executionAmount := big.NewInt(rawInjectCfg.executionAmount) loadTokenAmount, ok := new(big.Int).SetString(rawInjectCfg.loadTokenAmount, 10) if !ok { - errors.New("failed to load token amount") + return fmt.Sprint("failed to load token amount") } injectCfg.configPath = rawInjectCfg.configPath diff --git a/tools/iomigrater/cmds/migrate-db.go b/tools/iomigrater/cmds/migrate-db.go index 0af5bbf764..2108c4c841 100644 --- a/tools/iomigrater/cmds/migrate-db.go +++ b/tools/iomigrater/cmds/migrate-db.go @@ -86,7 +86,7 @@ func getProgressMod(num uint64) (int, int) { return numInt, step } -func migrateDbFile() error { +func migrateDbFile() (err error) { // Check flags if oldFile == "" { return fmt.Errorf("--old-file is empty") @@ -129,8 +129,8 @@ func migrateDbFile() error { } defer func() { - oldDAO.Stop(ctx) - newDAO.Stop(ctx) + err = oldDAO.Stop(ctx) + err = newDAO.Stop(ctx) }() // Show the progressbar @@ -152,12 +152,16 @@ func migrateDbFile() error { } if i%uint64(step) == 0 { - bar.Add(1) + if err = bar.Add(1); err != nil { + return fmt.Errorf("failed to add 1 on bar on height %d: %v", i, err) + } intHeight-- } } if intHeight > 0 { - bar.Add(intHeight) + if err = bar.Add(intHeight); err != nil { + return fmt.Errorf("failed to add %d on bar: %v", intHeight, err) + } } return nil