From b692e4c8583fb7f074b86c8b73de5c38648ebb76 Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Fri, 10 Nov 2023 00:48:32 +0100 Subject: [PATCH] chore: Improve errors readability --- pkg/relayer/proxy/errors.go | 14 +++++++------- pkg/relayer/proxy/proxy.go | 5 +++-- pkg/relayer/proxy/relay_verifier.go | 6 +++--- pkg/relayer/proxy/server_builder.go | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pkg/relayer/proxy/errors.go b/pkg/relayer/proxy/errors.go index 4a2cde538..6a0815b58 100644 --- a/pkg/relayer/proxy/errors.go +++ b/pkg/relayer/proxy/errors.go @@ -3,11 +3,11 @@ package proxy import sdkerrors "cosmossdk.io/errors" var ( - codespace = "relayer/proxy" - ErrUnsupportedRPCType = sdkerrors.Register(codespace, 1, "unsupported rpc type") - ErrInvalidRelayRequestSignature = sdkerrors.Register(codespace, 2, "invalid relay request signature") - ErrInvalidSession = sdkerrors.Register(codespace, 3, "invalid session") - ErrInvalidSupplier = sdkerrors.Register(codespace, 4, "invalid supplier") - ErrUndefinedSigningKeyName = sdkerrors.Register(codespace, 5, "undefined signing key name") - ErrUndefinedProxiedServicesEndpoints = sdkerrors.Register(codespace, 6, "undefined proxied services endpoints") + codespace = "relayer_proxy" + ErrRelayerProxyUnsupportedRPCType = sdkerrors.Register(codespace, 1, "unsupported relayer proxy rpc type") + ErrRelayerProxyInvalidRelayRequestSignature = sdkerrors.Register(codespace, 2, "invalid relay request signature") + ErrRelayerProxyInvalidSession = sdkerrors.Register(codespace, 3, "invalid session in relayer request") + ErrRelayerProxyInvalidSupplier = sdkerrors.Register(codespace, 4, "invalid relayer proxy supplier") + ErrRelayerProxyUndefinedSigningKeyName = sdkerrors.Register(codespace, 5, "undefined relayer proxy signing key name") + ErrRelayerProxyUndefinedProxiedServicesEndpoints = sdkerrors.Register(codespace, 6, "undefined proxied services endpoints for relayer proxy") ) diff --git a/pkg/relayer/proxy/proxy.go b/pkg/relayer/proxy/proxy.go index 4991d4658..ea73031c8 100644 --- a/pkg/relayer/proxy/proxy.go +++ b/pkg/relayer/proxy/proxy.go @@ -158,13 +158,14 @@ func (rp *relayerProxy) ServedRelays() observable.Observable[*types.Relay] { } // validateConfig validates the relayer proxy's configuration options and returns an error if it is invalid. +// TODO_TEST: Add tests for validating these configurations. func (rp *relayerProxy) validateConfig() error { if rp.signingKeyName == "" { - return ErrUndefinedSigningKeyName + return ErrRelayerProxyUndefinedSigningKeyName } if rp.proxiedServicesEndpoints == nil { - return ErrUndefinedProxiedServicesEndpoints + return ErrRelayerProxyUndefinedProxiedServicesEndpoints } return nil diff --git a/pkg/relayer/proxy/relay_verifier.go b/pkg/relayer/proxy/relay_verifier.go index 54f1685a4..db9cbe7dc 100644 --- a/pkg/relayer/proxy/relay_verifier.go +++ b/pkg/relayer/proxy/relay_verifier.go @@ -37,7 +37,7 @@ func (rp *relayerProxy) VerifyRelayRequest( } if !account.GetPubKey().VerifySignature(hash, relayRequest.Meta.Signature) { - return ErrInvalidRelayRequestSignature + return ErrRelayerProxyInvalidRelayRequestSignature } // Query for the current session to check if relayRequest sessionId matches the current session. @@ -62,7 +62,7 @@ func (rp *relayerProxy) VerifyRelayRequest( // matches the relayRequest sessionId. // TODO_INVESTIGATE: Revisit the assumptions above at some point in the future, but good enough for now. if session.SessionId != relayRequest.Meta.SessionHeader.SessionId { - return ErrInvalidSession + return ErrRelayerProxyInvalidSession } // Check if the relayRequest is allowed to be served by the relayer proxy. @@ -72,5 +72,5 @@ func (rp *relayerProxy) VerifyRelayRequest( } } - return ErrInvalidSupplier + return ErrRelayerProxyInvalidSupplier } diff --git a/pkg/relayer/proxy/server_builder.go b/pkg/relayer/proxy/server_builder.go index 42178e82c..a5abc47bd 100644 --- a/pkg/relayer/proxy/server_builder.go +++ b/pkg/relayer/proxy/server_builder.go @@ -48,7 +48,7 @@ func (rp *relayerProxy) BuildProvidedServices(ctx context.Context) error { rp, ) default: - return ErrUnsupportedRPCType + return ErrRelayerProxyUnsupportedRPCType } serviceEndpoints = append(serviceEndpoints, server)