From 931d54b0326b22664a17f50014751053fd61d852 Mon Sep 17 00:00:00 2001 From: Lorenz Herzberger Date: Fri, 19 Jul 2024 02:38:49 +0200 Subject: [PATCH] chore: add more info to error messages on machine queries Signed-off-by: Lorenz Herzberger --- x/machine/keeper/query_get_machine_by_public_key.go | 3 ++- x/machine/keeper/query_get_machine_by_public_key_test.go | 2 +- x/machine/keeper/query_get_trust_anchor_status.go | 3 ++- x/machine/keeper/query_get_trust_anchor_status_test.go | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/x/machine/keeper/query_get_machine_by_public_key.go b/x/machine/keeper/query_get_machine_by_public_key.go index b5d485d..ec03866 100644 --- a/x/machine/keeper/query_get_machine_by_public_key.go +++ b/x/machine/keeper/query_get_machine_by_public_key.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" "github.com/planetmint/planetmint-go/errormsg" "github.com/planetmint/planetmint-go/x/machine/types" @@ -20,7 +21,7 @@ func (k Keeper) GetMachineByPublicKey(goCtx context.Context, req *types.QueryGet machineIndex, found := k.GetMachineIndexByPubKey(ctx, req.PublicKey) if !found { - return nil, status.Error(codes.NotFound, "machine not found") + return nil, status.Error(codes.NotFound, fmt.Sprintf("machine not found by public key: %s", req.PublicKey)) } machine, found := k.GetMachine(ctx, machineIndex) diff --git a/x/machine/keeper/query_get_machine_by_public_key_test.go b/x/machine/keeper/query_get_machine_by_public_key_test.go index 5059aa2..de48db3 100644 --- a/x/machine/keeper/query_get_machine_by_public_key_test.go +++ b/x/machine/keeper/query_get_machine_by_public_key_test.go @@ -39,7 +39,7 @@ func TestGetMachineByPublicKey(t *testing.T) { }, { desc: "MachineNotFound", request: &types.QueryGetMachineByPublicKeyRequest{PublicKey: "invalid key"}, - err: status.Error(codes.NotFound, "machine not found"), + err: status.Error(codes.NotFound, "machine not found by public key: invalid key"), }, } { t.Run(tc.desc, func(t *testing.T) { diff --git a/x/machine/keeper/query_get_trust_anchor_status.go b/x/machine/keeper/query_get_trust_anchor_status.go index 32d4d61..792ca36 100644 --- a/x/machine/keeper/query_get_trust_anchor_status.go +++ b/x/machine/keeper/query_get_trust_anchor_status.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" "github.com/planetmint/planetmint-go/errormsg" "github.com/planetmint/planetmint-go/x/machine/types" @@ -20,7 +21,7 @@ func (k Keeper) GetTrustAnchorStatus(goCtx context.Context, req *types.QueryGetT _, activated, found := k.GetTrustAnchor(ctx, req.Machineid) if !found { - return nil, status.Error(codes.NotFound, "trust anchor not found") + return nil, status.Error(codes.NotFound, fmt.Sprintf("trust anchor not found by machine id: %s", req.Machineid)) } return &types.QueryGetTrustAnchorStatusResponse{Machineid: req.Machineid, Isactivated: activated}, nil diff --git a/x/machine/keeper/query_get_trust_anchor_status_test.go b/x/machine/keeper/query_get_trust_anchor_status_test.go index 81e5559..657e42c 100644 --- a/x/machine/keeper/query_get_trust_anchor_status_test.go +++ b/x/machine/keeper/query_get_trust_anchor_status_test.go @@ -35,7 +35,7 @@ func TestGetTrustAnchorQuery(t *testing.T) { { desc: "NotFound", request: &types.QueryGetTrustAnchorStatusRequest{Machineid: "invalid MachineID"}, - err: status.Error(codes.NotFound, "trust anchor not found"), + err: status.Error(codes.NotFound, "trust anchor not found by machine id: invalid MachineID"), }, } { t.Run(tc.desc, func(t *testing.T) {