From f26b04617aa382a85ef00a6245ab0ff5bf10482d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0lker=20G=2E=20=C3=96zt=C3=BCrk?= Date: Wed, 2 Feb 2022 13:29:20 +0300 Subject: [PATCH] fix(network): do not hide underlying err msg --- starport/pkg/cosmoserror/error.go | 4 ++-- starport/services/network/join.go | 17 +++++++---------- starport/services/network/launch.go | 9 ++++----- starport/services/network/publish.go | 13 ++++++------- starport/services/network/queries.go | 11 +++++------ starport/services/network/request.go | 13 ++++--------- 6 files changed, 28 insertions(+), 39 deletions(-) diff --git a/starport/pkg/cosmoserror/error.go b/starport/pkg/cosmoserror/error.go index 8c85eb4e74..023fa23e41 100644 --- a/starport/pkg/cosmoserror/error.go +++ b/starport/pkg/cosmoserror/error.go @@ -8,8 +8,8 @@ import ( ) var ( - ErrInternal = errors.New("some invariants expected by the underlying system has been broken") - ErrInvalidRequest = errors.New("invalid GRPC request argument or object not found") + ErrInternal = errors.New("internal error") + ErrInvalidRequest = errors.New("invalid request") ) func Unwrap(err error) error { diff --git a/starport/services/network/join.go b/starport/services/network/join.go index 732132cf99..b9ff2e9eb9 100644 --- a/starport/services/network/join.go +++ b/starport/services/network/join.go @@ -111,12 +111,12 @@ func (n Network) sendAccountRequest( n.ev.Send(events.New(events.StatusOngoing, "Broadcasting account transactions")) res, err := n.cosmos.BroadcastTx(n.account.Name, msg) if err != nil { - return cosmoserror.Unwrap(err) + return err } var requestRes launchtypes.MsgRequestAddAccountResponse if err := res.Decode(&requestRes); err != nil { - return cosmoserror.Unwrap(err) + return err } if requestRes.AutoApproved { @@ -162,12 +162,12 @@ func (n Network) sendValidatorRequest( res, err := n.cosmos.BroadcastTx(n.account.Name, msg) if err != nil { - return cosmoserror.Unwrap(err) + return err } var requestRes launchtypes.MsgRequestAddValidatorResponse if err := res.Decode(&requestRes); err != nil { - return cosmoserror.Unwrap(err) + return err } if requestRes.AutoApproved { @@ -187,8 +187,7 @@ func (n Network) hasValidator(ctx context.Context, launchID uint64, address stri LaunchID: launchID, Address: address, }) - err = cosmoserror.Unwrap(err) - if err == cosmoserror.ErrInvalidRequest { + if cosmoserror.Unwrap(err) == cosmoserror.ErrInvalidRequest { return false, nil } else if err != nil { return false, err @@ -202,8 +201,7 @@ func (n Network) hasAccount(ctx context.Context, launchID uint64, address string LaunchID: launchID, Address: address, }) - err = cosmoserror.Unwrap(err) - if err == cosmoserror.ErrInvalidRequest { + if cosmoserror.Unwrap(err) == cosmoserror.ErrInvalidRequest { return false, nil } else if err != nil { return false, err @@ -213,8 +211,7 @@ func (n Network) hasAccount(ctx context.Context, launchID uint64, address string LaunchID: launchID, Address: address, }) - err = cosmoserror.Unwrap(err) - if err == cosmoserror.ErrInvalidRequest { + if cosmoserror.Unwrap(err) == cosmoserror.ErrInvalidRequest { return false, nil } else if err != nil { return false, err diff --git a/starport/services/network/launch.go b/starport/services/network/launch.go index 34e604f843..fd873782bb 100644 --- a/starport/services/network/launch.go +++ b/starport/services/network/launch.go @@ -6,7 +6,6 @@ import ( "time" launchtypes "github.com/tendermint/spn/x/launch/types" - "github.com/tendermint/starport/starport/pkg/cosmoserror" "github.com/tendermint/starport/starport/pkg/events" "github.com/tendermint/starport/starport/pkg/xtime" "github.com/tendermint/starport/starport/services/network/networktypes" @@ -16,7 +15,7 @@ import ( func (n Network) LaunchParams(ctx context.Context) (launchtypes.Params, error) { res, err := launchtypes.NewQueryClient(n.cosmos.Context).Params(ctx, &launchtypes.QueryParamsRequest{}) if err != nil { - return launchtypes.Params{}, cosmoserror.Unwrap(err) + return launchtypes.Params{}, err } return res.GetParams(), nil } @@ -26,7 +25,7 @@ func (n Network) TriggerLaunch(ctx context.Context, launchID uint64, remainingTi n.ev.Send(events.New(events.StatusOngoing, fmt.Sprintf("Launching chain %d", launchID))) params, err := n.LaunchParams(ctx) if err != nil { - return cosmoserror.Unwrap(err) + return err } var ( @@ -52,12 +51,12 @@ func (n Network) TriggerLaunch(ctx context.Context, launchID uint64, remainingTi n.ev.Send(events.New(events.StatusOngoing, "Setting launch time")) res, err := n.cosmos.BroadcastTx(n.account.Name, msg) if err != nil { - return cosmoserror.Unwrap(err) + return err } var launchRes launchtypes.MsgTriggerLaunchResponse if err := res.Decode(&launchRes); err != nil { - return cosmoserror.Unwrap(err) + return err } n.ev.Send(events.New(events.StatusDone, diff --git a/starport/services/network/publish.go b/starport/services/network/publish.go index 71e9225969..4aafb02887 100644 --- a/starport/services/network/publish.go +++ b/starport/services/network/publish.go @@ -85,8 +85,7 @@ func (n Network) Publish(ctx context.Context, c Chain, options ...PublishOption) CoordinatorByAddress(ctx, &profiletypes.QueryGetCoordinatorByAddressRequest{ Address: coordinatorAddress, }) - err = cosmoserror.Unwrap(err) - if err == cosmoserror.ErrInvalidRequest { + if cosmoserror.Unwrap(err) == cosmoserror.ErrInvalidRequest { msgCreateCoordinator := profiletypes.NewMsgCreateCoordinator( coordinatorAddress, "", @@ -107,7 +106,7 @@ func (n Network) Publish(ctx context.Context, c Chain, options ...PublishOption) CampaignID: o.campaignID, }) if err != nil { - return 0, 0, cosmoserror.Unwrap(err) + return 0, 0, err } } else { msgCreateCampaign := campaigntypes.NewMsgCreateCampaign( @@ -117,12 +116,12 @@ func (n Network) Publish(ctx context.Context, c Chain, options ...PublishOption) ) res, err := n.cosmos.BroadcastTx(n.account.Name, msgCreateCampaign) if err != nil { - return 0, 0, cosmoserror.Unwrap(err) + return 0, 0, err } var createCampaignRes campaigntypes.MsgCreateCampaignResponse if err := res.Decode(&createCampaignRes); err != nil { - return 0, 0, cosmoserror.Unwrap(err) + return 0, 0, err } campaignID = createCampaignRes.CampaignID } @@ -139,12 +138,12 @@ func (n Network) Publish(ctx context.Context, c Chain, options ...PublishOption) ) res, err := n.cosmos.BroadcastTx(n.account.Name, msgCreateChain) if err != nil { - return 0, 0, cosmoserror.Unwrap(err) + return 0, 0, err } var createChainRes launchtypes.MsgCreateChainResponse if err := res.Decode(&createChainRes); err != nil { - return 0, 0, cosmoserror.Unwrap(err) + return 0, 0, err } return createChainRes.LaunchID, campaignID, nil diff --git a/starport/services/network/queries.go b/starport/services/network/queries.go index 2ad5608d1b..a67fee81c9 100644 --- a/starport/services/network/queries.go +++ b/starport/services/network/queries.go @@ -5,7 +5,6 @@ import ( "github.com/pkg/errors" launchtypes "github.com/tendermint/spn/x/launch/types" - "github.com/tendermint/starport/starport/pkg/cosmoserror" "github.com/tendermint/starport/starport/pkg/events" "github.com/tendermint/starport/starport/services/network/networktypes" ) @@ -18,7 +17,7 @@ func (n Network) ChainLaunch(ctx context.Context, id uint64) (networktypes.Chain LaunchID: id, }) if err != nil { - return networktypes.ChainLaunch{}, cosmoserror.Unwrap(err) + return networktypes.ChainLaunch{}, err } n.ev.Send(events.New(events.StatusOngoing, "Chain information fetched")) @@ -33,7 +32,7 @@ func (n Network) ChainLaunches(ctx context.Context) ([]networktypes.ChainLaunch, n.ev.Send(events.New(events.StatusOngoing, "Fetching chains information")) res, err := launchtypes.NewQueryClient(n.cosmos.Context).ChainAll(ctx, &launchtypes.QueryAllChainRequest{}) if err != nil { - return chainLaunches, cosmoserror.Unwrap(err) + return chainLaunches, err } // Parse fetched chains @@ -71,7 +70,7 @@ func (n Network) GenesisAccounts(ctx context.Context, launchID uint64) (genAccs LaunchID: launchID, }) if err != nil { - return genAccs, cosmoserror.Unwrap(err) + return genAccs, err } for _, acc := range res.GenesisAccount { @@ -88,7 +87,7 @@ func (n Network) VestingAccounts(ctx context.Context, launchID uint64) (vestingA LaunchID: launchID, }) if err != nil { - return vestingAccs, cosmoserror.Unwrap(err) + return vestingAccs, err } for i, acc := range res.VestingAccount { @@ -110,7 +109,7 @@ func (n Network) GenesisValidators(ctx context.Context, launchID uint64) (genVal LaunchID: launchID, }) if err != nil { - return genVals, cosmoserror.Unwrap(err) + return genVals, err } for _, acc := range res.GenesisValidator { diff --git a/starport/services/network/request.go b/starport/services/network/request.go index 1a56aaece8..398ac3dd5e 100644 --- a/starport/services/network/request.go +++ b/starport/services/network/request.go @@ -5,7 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" launchtypes "github.com/tendermint/spn/x/launch/types" - "github.com/tendermint/starport/starport/pkg/cosmoserror" "github.com/tendermint/starport/starport/pkg/events" "github.com/tendermint/starport/starport/services/network/networktypes" ) @@ -38,7 +37,7 @@ func (n Network) Requests(ctx context.Context, launchID uint64) ([]launchtypes.R LaunchID: launchID, }) if err != nil { - return nil, cosmoserror.Unwrap(err) + return nil, err } return res.Request, nil } @@ -50,7 +49,7 @@ func (n Network) Request(ctx context.Context, launchID, requestID uint64) (launc RequestID: requestID, }) if err != nil { - return launchtypes.Request{}, cosmoserror.Unwrap(err) + return launchtypes.Request{}, err } return res.Request, nil } @@ -84,13 +83,9 @@ func (n Network) SubmitRequest(launchID uint64, reviewal ...Reviewal) error { res, err := n.cosmos.BroadcastTx(n.account.Name, messages...) if err != nil { - return cosmoserror.Unwrap(err) + return err } var requestRes launchtypes.MsgSettleRequestResponse - err = res.Decode(&requestRes) - if err != nil { - return cosmoserror.Unwrap(err) - } - return nil + return res.Decode(&requestRes) }