diff --git a/x/proof/keeper/msg_server_create_claim.go b/x/proof/keeper/msg_server_create_claim.go index d9c4a32d3..f9e06055c 100644 --- a/x/proof/keeper/msg_server_create_claim.go +++ b/x/proof/keeper/msg_server_create_claim.go @@ -33,7 +33,7 @@ func (k msgServer) CreateClaim( // Basic validation of the CreateClaim message. if err = msg.ValidateBasic(); err != nil { - return nil, err + return nil, status.Error(codes.InvalidArgument, err.Error()) } logger.Info("validated the createClaim message") diff --git a/x/proof/keeper/msg_update_params.go b/x/proof/keeper/msg_update_params.go index 392f9333f..8b95781b2 100644 --- a/x/proof/keeper/msg_update_params.go +++ b/x/proof/keeper/msg_update_params.go @@ -2,20 +2,33 @@ package keeper import ( "context" + "fmt" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "github.com/pokt-network/poktroll/x/proof/types" ) func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + logger := k.Logger().With("method", "UpdateParams") + if err := req.ValidateBasic(); err != nil { - return nil, err + return nil, status.Error(codes.InvalidArgument, err.Error()) } if k.GetAuthority() != req.Authority { - return nil, types.ErrProofInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + return nil, status.Error( + codes.PermissionDenied, + types.ErrProofInvalidSigner.Wrapf( + "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority, + ).Error(), + ) } if err := k.SetParams(ctx, req.Params); err != nil { - return nil, err + err = fmt.Errorf("unable to set params: %w", err) + logger.Error(err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } return &types.MsgUpdateParamsResponse{}, nil diff --git a/x/proof/keeper/query_claim.go b/x/proof/keeper/query_claim.go index 520aa4b0c..399cf3f27 100644 --- a/x/proof/keeper/query_claim.go +++ b/x/proof/keeper/query_claim.go @@ -3,6 +3,7 @@ package keeper import ( "context" "encoding/binary" + "fmt" "cosmossdk.io/store/prefix" "github.com/cosmos/cosmos-sdk/runtime" @@ -14,6 +15,8 @@ import ( ) func (k Keeper) AllClaims(ctx context.Context, req *types.QueryAllClaimsRequest) (*types.QueryAllClaimsResponse, error) { + logger := k.Logger().With("method", "AllClaims") + if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -65,7 +68,9 @@ func (k Keeper) AllClaims(ctx context.Context, req *types.QueryAllClaimsRequest) // The value is the encoded claim. var claim types.Claim if err := k.cdc.Unmarshal(value, &claim); err != nil { - return err + err = fmt.Errorf("unable to unmarshal claim with key (hex): %x: %+v", key, err) + logger.Error(err.Error()) + return status.Error(codes.Internal, err.Error()) } claims = append(claims, claim) } diff --git a/x/proof/keeper/query_proof.go b/x/proof/keeper/query_proof.go index 12eae432c..f2a84ba42 100644 --- a/x/proof/keeper/query_proof.go +++ b/x/proof/keeper/query_proof.go @@ -14,6 +14,8 @@ import ( ) func (k Keeper) AllProofs(ctx context.Context, req *types.QueryAllProofsRequest) (*types.QueryAllProofsResponse, error) { + logger := k.Logger().With("method", "AllProofs") + if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -63,7 +65,9 @@ func (k Keeper) AllProofs(ctx context.Context, req *types.QueryAllProofsRequest) // The value is the encoded proof. var proof types.Proof if err := k.cdc.Unmarshal(value, &proof); err != nil { - return err + err = fmt.Errorf("unable to unmarshal proof with key (hex): %x: %+v", key, err) + logger.Error(err.Error()) + return status.Error(codes.Internal, err.Error()) } proofs = append(proofs, proof)