Skip to content

Commit 5084bb7

Browse files
committed
use value error
1 parent 0adb961 commit 5084bb7

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/sed/core/config.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@
2424
logger = setup_logging("config")
2525

2626

27-
class ConfigError(Exception):
28-
"""Exception raised for errors in the config file."""
29-
30-
def __init__(self, message: str):
31-
self.message = message
32-
super().__init__(self.message)
33-
34-
def __str__(self):
35-
return self.message
36-
37-
3827
def parse_config(
3928
config: dict | str = None,
4029
folder_config: dict | str = None,
@@ -73,7 +62,7 @@ def parse_config(
7362
Raises:
7463
TypeError: Raised if the provided file is neither *json* nor *yaml*.
7564
FileNotFoundError: Raised if the provided file is not found.
76-
ConfigError: Raised if there is a validation error in the config file.
65+
ValueError: Raised if there is a validation error in the config file.
7766
7867
Returns:
7968
dict: Loaded and completed config dict, possibly verified by pydantic config model.
@@ -171,7 +160,7 @@ def parse_config(
171160
for error in e.errors():
172161
error_msg += f"\n- {' -> '.join(str(loc) for loc in error['loc'])}: {error['msg']}"
173162
logger.error(error_msg)
174-
raise ConfigError(error_msg) from e
163+
raise ValueError(error_msg) from e
175164

176165

177166
def load_config(config_path: str) -> dict:

tests/test_config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import pytest
1111

1212
from sed.core.config import complete_dictionary
13-
from sed.core.config import ConfigError
1413
from sed.core.config import load_config
1514
from sed.core.config import parse_config
1615
from sed.core.config import save_config
@@ -168,7 +167,7 @@ def test_invalid_config_extra_field():
168167
)
169168
invalid_config = default_config.copy()
170169
invalid_config["extra_field"] = "extra_value"
171-
with pytest.raises(ConfigError):
170+
with pytest.raises(ValueError):
172171
parse_config(
173172
invalid_config,
174173
folder_config={},
@@ -188,7 +187,7 @@ def test_invalid_config_missing_field():
188187
)
189188
invalid_config = default_config.copy()
190189
del invalid_config["core"]["loader"]
191-
with pytest.raises(ConfigError):
190+
with pytest.raises(ValueError):
192191
parse_config(
193192
folder_config={},
194193
user_config={},
@@ -208,7 +207,7 @@ def test_invalid_config_wrong_values():
208207
)
209208
invalid_config = default_config.copy()
210209
invalid_config["core"]["loader"] = "nonexistent"
211-
with pytest.raises(ConfigError) as e:
210+
with pytest.raises(ValueError) as e:
212211
parse_config(
213212
folder_config={},
214213
user_config={},
@@ -222,7 +221,7 @@ def test_invalid_config_wrong_values():
222221
invalid_config["core"]["copy_tool"]["source"] = "./"
223222
invalid_config["core"]["copy_tool"]["dest"] = "./"
224223
invalid_config["core"]["copy_tool"]["gid"] = 9999
225-
with pytest.raises(ConfigError) as e:
224+
with pytest.raises(ValueError) as e:
226225
parse_config(
227226
folder_config={},
228227
user_config={},

0 commit comments

Comments
 (0)