From badc331d9b5fdc312877c9a62e8069aa9e830862 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 6 Feb 2023 11:09:44 +0100 Subject: [PATCH] updating errors returns in 09-localhost (#3105) --- modules/core/02-client/types/errors.go | 2 ++ .../light-clients/09-localhost/client_state.go | 17 +++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/core/02-client/types/errors.go b/modules/core/02-client/types/errors.go index 0c2bd65f339..39792948ae5 100644 --- a/modules/core/02-client/types/errors.go +++ b/modules/core/02-client/types/errors.go @@ -34,4 +34,6 @@ var ( ErrInvalidSubstitute = sdkerrors.Register(SubModuleName, 27, "invalid client state substitute") ErrInvalidUpgradeProposal = sdkerrors.Register(SubModuleName, 28, "invalid upgrade proposal") ErrClientNotActive = sdkerrors.Register(SubModuleName, 29, "client state is not active") + ErrFailedMembershipVerification = sdkerrors.Register(SubModuleName, 30, "membership verification failed") + ErrFailedNonMembershipVerification = sdkerrors.Register(SubModuleName, 31, "non-membership verification failed") ) diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index deda5cdcdb6..350fee7751f 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -93,24 +93,21 @@ func (cs ClientState) VerifyMembership( ) error { merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store bz := store.Get([]byte(merklePath.KeyPath[1])) if bz == nil { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(clienttypes.ErrFailedMembershipVerification, "value not found for path %s", path) } if !bytes.Equal(bz, value) { - return sdkerrors.Wrapf( - clienttypes.ErrFailedChannelStateVerification, - "todo: update error", - ) + return sdkerrors.Wrapf(clienttypes.ErrFailedMembershipVerification, "value provided does not equal value stored at path: %s", path) } return nil @@ -130,17 +127,17 @@ func (cs ClientState) VerifyNonMembership( ) error { merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path) + return sdkerrors.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath()) } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store bz := store.Get([]byte(merklePath.KeyPath[1])) if bz != nil { - return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- found for path %s", path) + return sdkerrors.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path) } return nil