Skip to content

Commit

Permalink
Fix ClientResponseError logging
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed Oct 4, 2023
1 parent 2a39432 commit 05ab146
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/commands/validators_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from web3 import Web3

from src.common.clients import consensus_client
from src.common.utils import log_verbose
from src.common.utils import format_error, log_verbose
from src.common.validators import validate_eth_address
from src.common.vault_config import VaultConfig
from src.config.settings import AVAILABLE_NETWORKS, NETWORKS, settings
Expand Down Expand Up @@ -199,7 +199,10 @@ async def main(count: int | None) -> None:
# Validator status is updated in CL after some delay.
# Status may be active in CL although validator has started exit process.
# CL will return status 400 for exit request in this case.
log_verbose(e)
click.secho(
f'{format_error(e)} for validator_index {exit_keystore.index}',
fg='yellow',
)
continue

exited_indexes.append(exit_keystore.index)
Expand Down
3 changes: 2 additions & 1 deletion src/common/startup_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from src.common.clients import db_client
from src.common.execution import check_hot_wallet_balance, get_oracles
from src.common.utils import log_verbose
from src.common.wallet import hot_wallet
from src.config.settings import settings
from src.validators.execution import check_deposit_data_root
Expand Down Expand Up @@ -118,7 +119,7 @@ async def collect_healthy_oracles() -> list:
healthy_oracles = []
for result in results:
if isinstance(result, Exception):
logger.error(repr(result))
log_verbose(result)
continue

if result:
Expand Down
16 changes: 15 additions & 1 deletion src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime, timezone
from pathlib import Path

import aiohttp
from eth_typing import BlockNumber, ChecksumAddress
from web3 import Web3
from web3.types import Timestamp, Wei
Expand Down Expand Up @@ -41,7 +42,20 @@ def log_verbose(e: Exception):
if settings.verbose:
logger.exception(e)
else:
logger.error(repr(e))
logger.error(format_error(e))


def format_error(e: Exception) -> str:
if isinstance(e, aiohttp.ClientResponseError):
# repr(e) gives too much output
return (
f'ClientResponseError('
f'status={e.status}, '
f'message="{e.message}", '
f'url="{e.request_info.url}")'
)

return repr(e)


async def wait_block_finalization(block_number: BlockNumber | None = None):
Expand Down
6 changes: 3 additions & 3 deletions src/exits/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from web3 import Web3

from src.common.typings import OracleApproval, Oracles, OraclesApproval
from src.common.utils import process_oracles_approvals
from src.common.utils import log_verbose, process_oracles_approvals
from src.config.settings import (
DEFAULT_RETRY_TIME,
OUTDATED_SIGNATURES_URL_PATH,
Expand Down Expand Up @@ -39,7 +39,7 @@ async def send_signature_rotation_requests(
session=session, replicas=replicas, payload=payload
)
except Exception as e:
logger.error(repr(e))
log_verbose(e)
continue
approvals[address] = response

Expand All @@ -60,7 +60,7 @@ async def send_signature_rotation_request_to_replicas(
try:
return await send_signature_rotation_request(session, endpoint, payload)
except (ClientError, asyncio.TimeoutError) as e:
logger.debug('%s for %s', repr(e), endpoint)
log_verbose(e)
last_error = e

if last_error:
Expand Down
8 changes: 5 additions & 3 deletions src/validators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from src.common.contracts import validators_registry_contract
from src.common.typings import OracleApproval, Oracles, OraclesApproval
from src.common.utils import process_oracles_approvals
from src.common.utils import format_error, process_oracles_approvals
from src.config.settings import DEFAULT_RETRY_TIME, ORACLES_VALIDATORS_TIMEOUT, settings
from src.validators.database import NetworkValidatorCrud
from src.validators.exceptions import (
Expand Down Expand Up @@ -61,7 +61,9 @@ async def send_approval_requests(oracles: Oracles, request: ApprovalRequest) ->
approvals: dict[ChecksumAddress, OracleApproval] = {}
for address, result in zip(oracles.addresses, results):
if isinstance(result, Exception):
logger.error(repr(result))
logger.error(
'All endpoints failed for oracle %s. Last error: %s', address, format_error(result)
)
continue

approvals[address] = result
Expand All @@ -83,7 +85,7 @@ async def send_approval_request_to_replicas(
try:
return await send_approval_request(session, endpoint, payload)
except (ClientError, asyncio.TimeoutError) as e:
logger.debug('%s for %s', repr(e), endpoint)
logger.warning('%s for endpoint %s', format_error(e), endpoint)
last_error = e

if last_error:
Expand Down

0 comments on commit 05ab146

Please sign in to comment.