From d25190853652839a7551555bfd82ac3832947ef5 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 20 Feb 2024 13:53:14 +0300 Subject: [PATCH] chore: moved logging unparsed messages to filterer --- pkg/converter/converter.go | 12 +++--------- pkg/filterer/filterer.go | 13 +++++++++++++ pkg/messages/msg_unparsed_message.go | 3 ++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pkg/converter/converter.go b/pkg/converter/converter.go index 9a4d0e4..d5e2cdc 100644 --- a/pkg/converter/converter.go +++ b/pkg/converter/converter.go @@ -150,16 +150,10 @@ func (c *Converter) ParseMessage( msgParsed, err := parser(message.Value, c.Chain, txResult.Height) if err != nil { - if c.Chain.LogUnparsedMessages { - c.Logger.Error().Err(err).Str("type", message.TypeUrl).Msg("Error parsing message") - return &messages.MsgUnparsedMessage{Error: fmt.Errorf("Error parsing message: %s", err)} + return &messages.MsgUnparsedMessage{ + MsgType: message.TypeUrl, + Error: fmt.Errorf("Error parsing message: %s", err), } - - c.Logger.Debug(). - Err(err). - Str("type", message.TypeUrl). - Msg("Not logging unparsed messages, skipping.") - return nil } else if msgParsed == nil { c.Logger.Error().Str("type", message.TypeUrl).Msg("Got empty message after parsing") return nil diff --git a/pkg/filterer/filterer.go b/pkg/filterer/filterer.go index d0c8fb6..cf8bd66 100644 --- a/pkg/filterer/filterer.go +++ b/pkg/filterer/filterer.go @@ -124,6 +124,19 @@ func (f *Filterer) FilterMessage(message types.Message, internal bool) types.Mes } } + if unparsedMsg, ok := message.(*messagesPkg.MsgUnparsedMessage); ok { + if f.Chain.LogUnparsedMessages { + f.Logger.Error().Err(unparsedMsg.Error).Str("type", unparsedMsg.MsgType).Msg("Error parsing message") + return message + } + + f.Logger.Debug(). + Err(unparsedMsg.Error). + Str("type", unparsedMsg.MsgType). + Msg("Not logging unparsed messages, skipping.") + return nil + } + // internal -> filter only if f.Chain.FilterInternalMessages is true // !internal -> filter regardless if !internal || f.Chain.FilterInternalMessages { diff --git a/pkg/messages/msg_unparsed_message.go b/pkg/messages/msg_unparsed_message.go index 4211807..4df79cc 100644 --- a/pkg/messages/msg_unparsed_message.go +++ b/pkg/messages/msg_unparsed_message.go @@ -8,7 +8,8 @@ import ( ) type MsgUnparsedMessage struct { - Error error + MsgType string + Error error } func (m MsgUnparsedMessage) Type() string {