Skip to content

Commit 59efc1f

Browse files
committed
Fix: error type.
1 parent 509cc21 commit 59efc1f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

cmdcomp/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import yaml
77
from pydantic import RootModel
88

9+
from cmdcomp.exception import ConfigFileExtensionError
910
from cmdcomp.v1.config import V1Config
1011
from cmdcomp.v2.config import V2Config
1112

@@ -17,8 +18,8 @@ class Config(RootModel):
1718

1819

1920
def load(file: BinaryIO) -> Config:
20-
_, extention = os.path.splitext(file.name)
21-
match extention:
21+
_, extension = os.path.splitext(file.name)
22+
match extension:
2223
case ".json":
2324
data = json.load(file)
2425

@@ -29,6 +30,6 @@ def load(file: BinaryIO) -> Config:
2930
data = tomllib.load(file)
3031

3132
case _:
32-
raise Exception(f"Unsupported config file type `{extention}`.")
33+
raise ConfigFileExtensionError(extension)
3334

3435
return Config.model_validate(data)

cmdcomp/exception.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
from typing import Never
22

33

4+
class ConfigFileExtensionError(Exception):
5+
def __init__(self, extension: str) -> None:
6+
self._extension = extension
7+
8+
def __str__(self) -> str:
9+
return f'config file extension "{self._extension}" is not supported.'
10+
11+
412
class NeverReach(Exception):
513
def __init__(self, value: Never) -> None:
614
self._value = value

0 commit comments

Comments
 (0)