Skip to content

Commit

Permalink
chore: moved logging unparsed messages to filterer
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Feb 20, 2024
1 parent 901a1fa commit d251908
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
12 changes: 3 additions & 9 deletions pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pkg/filterer/filterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/messages/msg_unparsed_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

type MsgUnparsedMessage struct {
Error error
MsgType string
Error error
}

func (m MsgUnparsedMessage) Type() string {
Expand Down

0 comments on commit d251908

Please sign in to comment.