Skip to content
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

[Code Health] fix: application module gRPC status error returns #954

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions x/application/keeper/msg_server_delegate_to_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pokt-network/poktroll/telemetry"
apptypes "github.com/pokt-network/poktroll/x/application/types"
Expand All @@ -24,14 +26,19 @@ func (k msgServer) DelegateToGateway(ctx context.Context, msg *apptypes.MsgDeleg

if err := msg.ValidateBasic(); err != nil {
logger.Error(fmt.Sprintf("Delegation Message failed basic validation: %v", err))
return nil, err
return nil, status.Error(codes.InvalidArgument, err.Error())
}

// Retrieve the application from the store
app, found := k.GetApplication(ctx, msg.AppAddress)
if !found {
logger.Info(fmt.Sprintf("Application not found with address [%s]", msg.AppAddress))
return nil, apptypes.ErrAppNotFound.Wrapf("application not found with address: %s", msg.AppAddress)
return nil, status.Error(
codes.NotFound,
apptypes.ErrAppNotFound.Wrapf(
"application not found with address: %s", msg.AppAddress,
).Error(),
)
}
logger.Info(fmt.Sprintf("Application found with address [%s]", msg.AppAddress))

Expand Down
4 changes: 3 additions & 1 deletion x/application/keeper/msg_server_undelegate_from_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"slices"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pokt-network/poktroll/telemetry"
apptypes "github.com/pokt-network/poktroll/x/application/types"
Expand All @@ -25,7 +27,7 @@ func (k msgServer) UndelegateFromGateway(ctx context.Context, msg *apptypes.MsgU
// Basic validation of the message
if err := msg.ValidateBasic(); err != nil {
logger.Error(fmt.Sprintf("Undelegation Message failed basic validation: %v", err))
return nil, err
return nil, status.Error(codes.InvalidArgument, err.Error())
}

// Retrieve the application from the store
Expand Down
2 changes: 1 addition & 1 deletion x/application/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (k msgServer) UpdateParam(ctx context.Context, msg *apptypes.MsgUpdateParam
)

if err := msg.ValidateBasic(); err != nil {
return nil, err
return nil, status.Error(codes.InvalidArgument, err.Error())
}

if k.GetAuthority() != msg.Authority {
Expand Down
19 changes: 16 additions & 3 deletions x/application/keeper/msg_update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/application/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.ErrAppInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority)
return nil, status.Error(
codes.InvalidArgument,
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
types.ErrAppInvalidSigner.Wrapf(
"invalid authority; expected %s, got %s",
k.GetAuthority(), req.Authority,
).Error(),
)
}

if err := k.SetParams(ctx, req.Params); err != nil {
return nil, err
logger.Error(fmt.Sprintf("setting params: %+v", err))
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
return nil, status.Error(codes.Internal, err.Error())
}

return &types.MsgUpdateParamsResponse{}, nil
Expand Down
Loading