Skip to content

Commit

Permalink
use value error
Browse files Browse the repository at this point in the history
  • Loading branch information
zain-sohail committed Jan 14, 2025
1 parent 0adb961 commit 5084bb7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
15 changes: 2 additions & 13 deletions src/sed/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@
logger = setup_logging("config")


class ConfigError(Exception):
"""Exception raised for errors in the config file."""

def __init__(self, message: str):
self.message = message
super().__init__(self.message)

def __str__(self):
return self.message


def parse_config(
config: dict | str = None,
folder_config: dict | str = None,
Expand Down Expand Up @@ -73,7 +62,7 @@ def parse_config(
Raises:
TypeError: Raised if the provided file is neither *json* nor *yaml*.
FileNotFoundError: Raised if the provided file is not found.
ConfigError: Raised if there is a validation error in the config file.
ValueError: Raised if there is a validation error in the config file.
Returns:
dict: Loaded and completed config dict, possibly verified by pydantic config model.
Expand Down Expand Up @@ -171,7 +160,7 @@ def parse_config(
for error in e.errors():
error_msg += f"\n- {' -> '.join(str(loc) for loc in error['loc'])}: {error['msg']}"
logger.error(error_msg)
raise ConfigError(error_msg) from e
raise ValueError(error_msg) from e


def load_config(config_path: str) -> dict:
Expand Down
9 changes: 4 additions & 5 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import pytest

from sed.core.config import complete_dictionary
from sed.core.config import ConfigError
from sed.core.config import load_config
from sed.core.config import parse_config
from sed.core.config import save_config
Expand Down Expand Up @@ -168,7 +167,7 @@ def test_invalid_config_extra_field():
)
invalid_config = default_config.copy()
invalid_config["extra_field"] = "extra_value"
with pytest.raises(ConfigError):
with pytest.raises(ValueError):
parse_config(
invalid_config,
folder_config={},
Expand All @@ -188,7 +187,7 @@ def test_invalid_config_missing_field():
)
invalid_config = default_config.copy()
del invalid_config["core"]["loader"]
with pytest.raises(ConfigError):
with pytest.raises(ValueError):
parse_config(
folder_config={},
user_config={},
Expand All @@ -208,7 +207,7 @@ def test_invalid_config_wrong_values():
)
invalid_config = default_config.copy()
invalid_config["core"]["loader"] = "nonexistent"
with pytest.raises(ConfigError) as e:
with pytest.raises(ValueError) as e:
parse_config(
folder_config={},
user_config={},
Expand All @@ -222,7 +221,7 @@ def test_invalid_config_wrong_values():
invalid_config["core"]["copy_tool"]["source"] = "./"
invalid_config["core"]["copy_tool"]["dest"] = "./"
invalid_config["core"]["copy_tool"]["gid"] = 9999
with pytest.raises(ConfigError) as e:
with pytest.raises(ValueError) as e:
parse_config(
folder_config={},
user_config={},
Expand Down

0 comments on commit 5084bb7

Please sign in to comment.