chore: add more info to error messages on machine queries

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2024-07-19 02:38:49 +02:00
parent 1b5814f88f
commit 931d54b032
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
4 changed files with 6 additions and 4 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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

View File

@ -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) {