From 328f4303090df1cca88777900da8af5d15e28314 Mon Sep 17 00:00:00 2001 From: Campbell Alden Date: Sun, 2 Aug 2026 22:49:38 +0900 Subject: [PATCH] Rename parsing error to be more reusable --- src/config/logging.py | 4 ++-- src/config/parse.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/config/logging.py b/src/config/logging.py index 43a3071..b77dd08 100644 --- a/src/config/logging.py +++ b/src/config/logging.py @@ -2,7 +2,7 @@ from typing import Any from dataclasses import dataclass import logging -from .parse import assert_key_of_type, ConfigParseError +from .parse import assert_key_of_type, ParseError LOG_LEVELS = { 'critical': logging.CRITICAL, @@ -25,7 +25,7 @@ class Logging: assert_key_of_type(config, 'level', str) log_level_setting = config['level'] if log_level_setting not in LOG_LEVELS: - raise ConfigParseError( + raise ParseError( ['level'], f'unknown log level "{log_level_setting}". Expected one of: {", ".join(LOG_LEVELS.keys())}' ) diff --git a/src/config/parse.py b/src/config/parse.py index c50df3f..2faea78 100644 --- a/src/config/parse.py +++ b/src/config/parse.py @@ -1,7 +1,7 @@ from typing import Any, TypeVar, Callable -class ConfigParseError(Exception): +class ParseError(Exception): """An error for when parsing a config fails""" def __init__(self, keypath: list[str], issue: str): @@ -14,10 +14,10 @@ class ConfigParseError(Exception): def assert_key_of_type(config: dict[str, Any], key: str, kind: Any): if key not in config: - raise ConfigParseError([key], 'missing') + raise ParseError([key], 'missing') if not isinstance(config[key], kind): - raise ConfigParseError([key], f'type of "{key}" was {type(config[key])}, expected {kind}') + raise ParseError([key], f'type of "{key}" was {type(config[key])}, expected {kind}') T = TypeVar('T') @@ -27,5 +27,5 @@ def parse_nested_config(config: dict[str, Any], key: str, parse: Callable[[dict[ assert_key_of_type(config, key, dict) try: return parse(config[key]) - except ConfigParseError as e: - raise ConfigParseError([key, *e.keypath], e.issue) + except ParseError as e: + raise ParseError([key, *e.keypath], e.issue)