From 6dda8370f477474c86dd3830b499b55b8d1892a2 Mon Sep 17 00:00:00 2001 From: Matthew Pendrey Date: Mon, 9 Dec 2024 09:29:32 +0000 Subject: [PATCH] error handling --- .../services/relay/evm/read/multieventtype.go | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/core/services/relay/evm/read/multieventtype.go b/core/services/relay/evm/read/multieventtype.go index 0b7b29e783c..da83f444601 100644 --- a/core/services/relay/evm/read/multieventtype.go +++ b/core/services/relay/evm/read/multieventtype.go @@ -27,10 +27,24 @@ type EventQuery struct { func MultiEventTypeQuery(ctx context.Context, lp logpoller.LogPoller, eventQueries []EventQuery, limitAndSort query.LimitAndSort) (iter.Seq2[string, commontypes.Sequence], error) { seqIter, err := multiEventTypeQueryWithoutErrorWrapping(ctx, lp, eventQueries, limitAndSort) if err != nil { - return nil, newMultiEventTypeQueryError(eventQueries, err) + if len(eventQueries) > 0 { + var calls []Call + for _, eq := range eventQueries { + calls = append(calls, Call{ + ContractAddress: eq.Address, + ContractName: eq.EventBinding.contractName, + ReadName: eq.EventBinding.eventName, + ReturnVal: eq.SequenceDataType, + }) + } + + err = newErrorFromCalls(err, calls, "", eventReadType) + } else { + err = fmt.Errorf("no event queries provided: %w", err) + } } - return seqIter, nil + return seqIter, err } func multiEventTypeQueryWithoutErrorWrapping(ctx context.Context, lp logpoller.LogPoller, eventQueries []EventQuery, limitAndSort query.LimitAndSort) (iter.Seq2[string, commontypes.Sequence], error) { @@ -53,7 +67,7 @@ func multiEventTypeQueryWithoutErrorWrapping(ctx context.Context, lp logpoller.L remapped, remapErr := eq.EventBinding.remap(eq.Filter) if remapErr != nil { - return nil, newMultiEventTypeQueryError(eventQueries, fmt.Errorf("error remapping filter: %w", remapErr)) + return nil, fmt.Errorf("error remapping filter: %w", remapErr) } expressions = append(expressions, remapped.Expressions...) @@ -83,25 +97,6 @@ func multiEventTypeQueryWithoutErrorWrapping(ctx context.Context, lp logpoller.L return seqIter, nil } -func newMultiEventTypeQueryError(eventQueries []EventQuery, err error) error { - if len(eventQueries) > 0 { - var calls []Call - for _, eq := range eventQueries { - calls = append(calls, Call{ - ContractAddress: eq.Address, - ContractName: eq.EventBinding.contractName, - ReadName: eq.EventBinding.eventName, - ReturnVal: eq.SequenceDataType, - }) - } - - err = newErrorFromCalls(err, calls, "", eventReadType) - } else { - err = fmt.Errorf("no event queries provided: %w", err) - } - return err -} - func decodeMultiEventTypeLogsIntoSequences(ctx context.Context, logs []logpoller.Log, eventQueries []EventQuery) (iter.Seq2[string, commontypes.Sequence], error) { type sequenceWithKey struct { Key string