Skip to content

Commit

Permalink
fix: use warnings instead of erroring in config network processing (#658
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
antazoey authored Apr 14, 2022
1 parent 990e1de commit 453b0a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
19 changes: 13 additions & 6 deletions src/ape/managers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

import pytest

from ape.exceptions import ConfigError
from ape.managers.config import DeploymentConfigCollection

DEPLOYMENTS = {
Expand All @@ -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

0 comments on commit 453b0a9

Please sign in to comment.