Skip to content

Commit

Permalink
chore(golang): Clarify error messages (#8677)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and mhofman committed Feb 18, 2024
1 parent 29bc63d commit 95e9aca
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion golang/cosmos/x/swingset/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func NewCmdSubmitCoreEvalProposal() *cobra.Command {
Specify at least one pair of permit.json and code.js files`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args)%2 != 0 {
return fmt.Errorf("must specify an even number of permit.json and code.js files")
return fmt.Errorf("must specify paired permit.json and code.js files")
}

clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
2 changes: 1 addition & 1 deletion golang/cosmos/x/swingset/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier
case LegacyQueryKeys:
return legacyQueryKeys(ctx, strings.Join(path[1:], "/"), req, keeper, legacyQuerierCdc)
default:
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown swingset query endpoint")
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown swingset query path")
}
}
}
Expand Down
31 changes: 15 additions & 16 deletions golang/cosmos/x/swingset/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"encoding/json"
"errors"
"fmt"

vstoragetypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -25,18 +26,16 @@ func NewEgress(nickname string, peer sdk.AccAddress, powerFlags []string) *Egres
}
}

// FIXME: Should have @endo/nat
// Nat is analogous to @endo/nat
// https://github.com/endojs/endo/blob/master/packages/nat
func Nat(num float64) (uint64, error) {
if num < 0 {
return 0, errors.New("Not a natural")
}

nat := uint64(num)
if float64(nat) != num {
return 0, errors.New("Not a precise integer")
if 0 <= num && num < (1<<53) {
nat := uint64(num)
if float64(nat) == num {
return nat, nil
}
}

return nat, nil
return 0, errors.New("Not a Nat")
}

type Messages struct {
Expand All @@ -60,11 +59,11 @@ func UnmarshalMessagesJSON(jsonString string) (ret *Messages, err error) {

ackFloat, ok := packet[1].(float64)
if !ok {
return nil, errors.New("Ack is not an integer")
return nil, errors.New("Ack is not a number")
}
ret.Ack, err = Nat(ackFloat)
if err != nil {
return nil, err
return nil, errors.New("Ack is not a Nat")
}

msgs, ok := packet[0].([]interface{})
Expand All @@ -77,21 +76,21 @@ func UnmarshalMessagesJSON(jsonString string) (ret *Messages, err error) {
for i, rawMsg := range msgs {
arrMsg, ok := rawMsg.([]interface{})
if !ok || len(arrMsg) != 2 {
return nil, errors.New("Message is not a pair")
return nil, fmt.Errorf("Messages[%d] is not a pair", i)
}

numFloat, ok := arrMsg[0].(float64)
if !ok {
return nil, errors.New("Message Num is not an integer")
return nil, fmt.Errorf("Messages[%d] Num is not a number", i)
}
ret.Nums[i], err = Nat(numFloat)
if err != nil {
return nil, errors.New("Message num is not a Nat")
return nil, fmt.Errorf("Messages[%d] Num is not a Nat", i)
}

ret.Messages[i], ok = arrMsg[1].(string)
if !ok {
return nil, errors.New("Message is not a string")
return nil, fmt.Errorf("Messages[%d] body is not a string", i)
}
}

Expand Down
2 changes: 1 addition & 1 deletion golang/cosmos/x/vbank/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return queryState(ctx, path[1:], req, k, legacyQuerierCdc)

default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0])
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown vbank query path")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion golang/cosmos/x/vstorage/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier
}
return queryChildren(ctx, entryPath, req, keeper, legacyQuerierCdc)
default:
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown vstorage query endpoint")
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown vstorage query path")
}
}
}
Expand Down

0 comments on commit 95e9aca

Please sign in to comment.