8000 fix(network): do not hide underlying err msg by ilgooz · Pull Request #2050 · ignite/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(network): do not hide underlying err msg #2050

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

Merged
merged 1 commit into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions starport/pkg/cosmoserror/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 7 additions & 10 deletions starport/services/network/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions starport/services/network/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand All @@ -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 (
Expand All @@ -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,
Expand Down
13 changes: 6 additions & 7 deletions starport/services/network/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"",
Expand All @@ -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(
Expand All @@ -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
}
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions starport/services/network/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"))
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
13 changes: 4 additions & 9 deletions starport/services/network/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
0