From 453b0a9346207193c93a9bfd7abdab4b38a2b251 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Thu, 14 Apr 2022 16:02:18 -0500 Subject: [PATCH] fix: use warnings instead of erroring in config network processing (#658) * fix: only warn in config processing in case not installed yet * test: fix test * test: fix test... again * fix: skip over when fails * fix: skip over when fails --- src/ape/managers/config.py | 19 +++++++++++++------ tests/functional/test_config.py | 10 +++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/ape/managers/config.py b/src/ape/managers/config.py index 797fc11388..52f287841a 100644 --- a/src/ape/managers/config.py +++ b/src/ape/managers/config.py @@ -7,7 +7,7 @@ from pydantic import root_validator from ape.api import ConfigDict, DependencyAPI, PluginConfig -from ape.exceptions import ConfigError +from ape.exceptions import ConfigError, NetworkError from ape.logging import logger from ape.utils import BaseInterfaceModel, load_config, to_address @@ -29,18 +29,21 @@ def __init__( ): for ecosystem_name, networks in data.items(): if ecosystem_name not in valid_ecosystem_names: - raise ConfigError(f"Invalid ecosystem '{ecosystem_name}' in deployments config.") + logger.warning(f"Invalid ecosystem '{ecosystem_name}' in deployments config.") + continue for network_name, contract_deployments in networks.items(): if network_name not in valid_network_names: - raise ConfigError(f"Invalid network '{network_name}' in deployments config.") + logger.warning(f"Invalid network '{network_name}' in deployments config.") + continue for deployment in [d for d in contract_deployments]: if "address" not in deployment: - raise ConfigError( + logger.warning( f"Missing 'address' field in deployment " f"(ecosystem={ecosystem_name}, network={network_name})" ) + continue address = deployment["address"] if isinstance(address, int): @@ -49,7 +52,7 @@ def __init__( try: deployment["address"] = to_address(address) except ValueError as err: - raise ConfigError(str(err)) from err + logger.warning(str(err)) super().__init__(data) @@ -142,7 +145,11 @@ def _plugin_configs(self) -> Dict[str, PluginConfig]: self.default_ecosystem = configs["default_ecosystem"] = user_config.pop( "default_ecosystem", "ethereum" ) - self.network_manager.set_default_ecosystem(self.default_ecosystem) + + try: + self.network_manager.set_default_ecosystem(self.default_ecosystem) + except NetworkError as err: + logger.warning(str(err)) dependencies = user_config.pop("dependencies", []) or [] if not isinstance(dependencies, list): diff --git a/tests/functional/test_config.py b/tests/functional/test_config.py index 699e742de9..a7102f8f68 100644 --- a/tests/functional/test_config.py +++ b/tests/functional/test_config.py @@ -1,6 +1,7 @@ +import logging + import pytest -from ape.exceptions import ConfigError from ape.managers.config import DeploymentConfigCollection DEPLOYMENTS = { @@ -23,8 +24,7 @@ def test_integer_deployment_addresses(): "ecosystems,networks,err_part", [(["fantom"], ["mainnet"], "ecosystem"), (["ethereum"], ["local"], "network")], ) -def test_bad_value_in_deployments(ecosystems, networks, err_part): - with pytest.raises(ConfigError) as err: +def test_bad_value_in_deployments(ecosystems, networks, err_part, caplog): + with caplog.at_level(logging.WARNING): DeploymentConfigCollection(DEPLOYMENTS, ecosystems, networks) - - assert f"Invalid {err_part}" in str(err.value) + assert f"Invalid {err_part}" in caplog.records[0].message