Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove logging of user errors #271

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ func handleError[T any](log zerolog.Logger, err error) (T, error) {
// as per specification returning nil and nil for not found resources
return zero, nil
}
if errors.Is(err, requester.ErrOutOfRange) {
return zero, fmt.Errorf("requested height is out of supported range")
}

log.Error().Err(err).Msg("api error")
return zero, errs.ErrInternal
Expand Down
53 changes: 36 additions & 17 deletions services/requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
_ "embed"
"encoding/hex"
"errors"
"fmt"
"math"
"math/big"
Expand All @@ -24,7 +25,7 @@ import (
"github.com/rs/zerolog"
"golang.org/x/sync/errgroup"

"github.com/onflow/flow-evm-gateway/api/errors"
errs "github.com/onflow/flow-evm-gateway/api/errors"
"github.com/onflow/flow-evm-gateway/config"
"github.com/onflow/flow-evm-gateway/storage"
)
Expand Down Expand Up @@ -155,7 +156,7 @@ func (e *EVM) SendRawTransaction(ctx context.Context, data []byte) (common.Hash,
}

if tx.GasPrice().Cmp(e.config.GasPrice) < 0 {
return common.Hash{}, errors.NewErrGasPriceTooLow(e.config.GasPrice)
return common.Hash{}, errs.NewErrGasPriceTooLow(e.config.GasPrice)
}

hexEncodedTx, err := cadence.NewString(hex.EncodeToString(data))
Expand Down Expand Up @@ -214,11 +215,14 @@ func (e *EVM) GetBalance(
[]cadence.Value{hexEncodedAddress},
)
if err != nil {
e.logger.Error().
Err(err).
Str("address", address.String()).
Uint64("cadence-height", height).
Msg("failed to get get balance")
if !errors.Is(err, ErrOutOfRange) {
e.logger.Error().
Err(err).
Str("address", address.String()).
Int64("evm-height", evmHeight).
Uint64("cadence-height", height).
Msg("failed to get get balance")
}
return nil, fmt.Errorf("failed to get balance: %w", err)
}

Expand Down Expand Up @@ -252,10 +256,13 @@ func (e *EVM) GetNonce(
[]cadence.Value{hexEncodedAddress},
)
if err != nil {
e.logger.Error().Err(err).
Str("address", address.String()).
Uint64("cadence-height", height).
Msg("failed to get nonce")
if !errors.Is(err, ErrOutOfRange) {
e.logger.Error().Err(err).
Str("address", address.String()).
Int64("evm-height", evmHeight).
Uint64("cadence-height", height).
Msg("failed to get nonce")
}
return 0, fmt.Errorf("failed to get nonce: %w", err)
}

Expand Down Expand Up @@ -303,12 +310,15 @@ func (e *EVM) Call(
[]cadence.Value{hexEncodedTx, hexEncodedAddress},
)
if err != nil {
e.logger.Error().
Err(err).
Uint64("cadence-height", height).
Str("from", from.String()).
Str("data", string(data)).
Msg("failed to execute call")
if !errors.Is(err, ErrOutOfRange) {
e.logger.Error().
Err(err).
Uint64("cadence-height", height).
Int64("evm-height", evmHeight).
Str("from", from.String()).
Str("data", string(data)).
Msg("failed to execute call")
}
return nil, fmt.Errorf("failed to execute script: %w", err)
}

Expand Down Expand Up @@ -399,6 +409,15 @@ func (e *EVM) GetCode(
[]cadence.Value{hexEncodedAddress},
)
if err != nil {
if !errors.Is(err, ErrOutOfRange) {
e.logger.Error().
Err(err).
Uint64("cadence-height", height).
Int64("evm-height", evmHeight).
Str("address", address.String()).
Msg("failed to get code")
}

return nil, fmt.Errorf("failed to execute script for get code: %w", err)
}

Expand Down
Loading