From fe0ff5905cff9cf56202c9958bda8e552eb30b36 Mon Sep 17 00:00:00 2001 From: satawatnack Date: Mon, 25 Nov 2024 15:07:50 +0700 Subject: [PATCH] update error msg --- x/tunnel/types/errors.go | 30 ++++++++++++++---------------- x/tunnel/types/msgs.go | 2 +- x/tunnel/types/packet.go | 6 +++++- x/tunnel/types/tunnel.go | 7 ++++++- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/x/tunnel/types/errors.go b/x/tunnel/types/errors.go index fa8cb33f5..badbb1605 100644 --- a/x/tunnel/types/errors.go +++ b/x/tunnel/types/errors.go @@ -11,20 +11,18 @@ var ( ErrIntervalOutOfRange = errorsmod.Register(ModuleName, 4, "interval out of range") ErrDeviationOutOfRange = errorsmod.Register(ModuleName, 5, "deviation out of range") ErrTunnelNotFound = errorsmod.Register(ModuleName, 6, "tunnel not found") - ErrNoRoute = errorsmod.Register(ModuleName, 7, "no route") - ErrNoReceipt = errorsmod.Register(ModuleName, 8, "no receipt") - ErrLatestPricesNotFound = errorsmod.Register(ModuleName, 9, "latest prices not found") - ErrPacketNotFound = errorsmod.Register(ModuleName, 10, "packet not found") - ErrNoPacketReceipt = errorsmod.Register(ModuleName, 11, "no packet receipt") - ErrInvalidTunnelCreator = errorsmod.Register(ModuleName, 12, "invalid creator of the tunnel") - ErrAccountAlreadyExist = errorsmod.Register(ModuleName, 13, "account already exist") - ErrInvalidRoute = errorsmod.Register(ModuleName, 14, "invalid tunnel route") - ErrInactiveTunnel = errorsmod.Register(ModuleName, 15, "inactive tunnel") - ErrAlreadyActive = errorsmod.Register(ModuleName, 16, "already active") - ErrAlreadyInactive = errorsmod.Register(ModuleName, 17, "already inactive") - ErrInvalidDepositDenom = errorsmod.Register(ModuleName, 18, "invalid deposit denom") - ErrDepositNotFound = errorsmod.Register(ModuleName, 19, "deposit not found") - ErrInsufficientDeposit = errorsmod.Register(ModuleName, 20, "insufficient deposit") - ErrInsufficientFund = errorsmod.Register(ModuleName, 21, "insufficient fund") - ErrDeviationNotFound = errorsmod.Register(ModuleName, 22, "deviation not found") + ErrLatestPricesNotFound = errorsmod.Register(ModuleName, 7, "latest prices not found") + ErrPacketNotFound = errorsmod.Register(ModuleName, 8, "packet not found") + ErrNoPacketReceipt = errorsmod.Register(ModuleName, 9, "no packet receipt") + ErrInvalidTunnelCreator = errorsmod.Register(ModuleName, 10, "invalid creator of the tunnel") + ErrAccountAlreadyExist = errorsmod.Register(ModuleName, 11, "account already exist") + ErrInvalidRoute = errorsmod.Register(ModuleName, 12, "invalid tunnel route") + ErrInactiveTunnel = errorsmod.Register(ModuleName, 13, "inactive tunnel") + ErrAlreadyActive = errorsmod.Register(ModuleName, 14, "already active") + ErrAlreadyInactive = errorsmod.Register(ModuleName, 15, "already inactive") + ErrInvalidDepositDenom = errorsmod.Register(ModuleName, 16, "invalid deposit denom") + ErrDepositNotFound = errorsmod.Register(ModuleName, 17, "deposit not found") + ErrInsufficientDeposit = errorsmod.Register(ModuleName, 18, "insufficient deposit") + ErrInsufficientFund = errorsmod.Register(ModuleName, 19, "insufficient fund") + ErrDeviationNotFound = errorsmod.Register(ModuleName, 20, "deviation not found") ) diff --git a/x/tunnel/types/msgs.go b/x/tunnel/types/msgs.go index d3d97913d..74d61931e 100644 --- a/x/tunnel/types/msgs.go +++ b/x/tunnel/types/msgs.go @@ -70,7 +70,7 @@ func NewMsgCreateTSSTunnel( func (m MsgCreateTunnel) GetRouteValue() (RouteI, error) { r, ok := m.Route.GetCachedValue().(RouteI) if !ok { - return nil, ErrNoRoute.Wrap("failed to get route") + return nil, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (RouteI)(nil), m.Route.GetCachedValue()) } return r, nil } diff --git a/x/tunnel/types/packet.go b/x/tunnel/types/packet.go index 55bf5c15d..066243c58 100644 --- a/x/tunnel/types/packet.go +++ b/x/tunnel/types/packet.go @@ -59,7 +59,11 @@ func (p *Packet) SetReceipt(receipt PacketReceiptI) error { func (p Packet) GetReceiptValue() (PacketReceiptI, error) { r, ok := p.Receipt.GetCachedValue().(PacketReceiptI) if !ok { - return nil, sdkerrors.ErrPackAny.Wrapf("cannot unpack route") + return nil, sdkerrors.ErrInvalidType.Wrapf( + "expected %T, got %T", + (PacketReceiptI)(nil), + p.Receipt.GetCachedValue(), + ) } return r, nil diff --git a/x/tunnel/types/tunnel.go b/x/tunnel/types/tunnel.go index 10ba43ec2..b753fd03c 100644 --- a/x/tunnel/types/tunnel.go +++ b/x/tunnel/types/tunnel.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" feedstypes "github.com/bandprotocol/chain/v3/x/feeds/types" ) @@ -77,7 +78,11 @@ func (t *Tunnel) SetRoute(route RouteI) error { func (t Tunnel) GetRouteValue() (RouteI, error) { r, ok := t.Route.GetCachedValue().(RouteI) if !ok { - return nil, ErrNoRoute.Wrap("failed to get route") + return nil, sdkerrors.ErrInvalidType.Wrapf( + "expected %T, got %T", + (RouteI)(nil), + t.Route.GetCachedValue(), + ) } return r, nil