Skip to content

Commit

Permalink
refactor: use cfg err
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Jun 18, 2024
1 parent bb2d90e commit 9a7f06b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/ape/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def update(root: dict, value_map: dict):

return root

return cls(**update(default_values, overrides))
data = update(default_values, overrides)
try:
return cls.model_validate(data)
except ValidationError as err:
raise ConfigError(str(err)) from err

@only_raise_attribute_error
def __getattr__(self, attr_name: str) -> Any:
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Optional, Union

import pytest
from pydantic import ValidationError
from pydantic_settings import SettingsConfigDict

from ape.api.config import ApeConfig, ConfigEnum, PluginConfig
Expand Down Expand Up @@ -425,14 +424,14 @@ def test_get_config_unknown_plugin(config):
def test_get_config_invalid_plugin_config(project):
with project.temp_config(node={"ethereum": [1, 2]}):
# Show project's ApeConfig model works.
with pytest.raises(ValidationError):
with pytest.raises(ConfigError):
project.config.get_config("node")

# Show the manager-wrapper also works
# (simple wrapper for local project's config,
# but at one time pointlessly overrode the `get_config()`
# which caused issues).
with pytest.raises(ValidationError):
with pytest.raises(ConfigError):
project.config_manager.get_config("node")


Expand Down

0 comments on commit 9a7f06b

Please sign in to comment.