|
9 | 9 | import json |
10 | 10 | from typing import TYPE_CHECKING, Any, Optional |
11 | 11 | from pydantic import ValidationError |
12 | | -from pydantic_core import InitErrorDetails |
13 | 12 | from typing_extensions import Self |
14 | 13 | from collections.abc import Mapping |
15 | 14 | import logging |
@@ -217,50 +216,34 @@ def load_settings(self) -> None: |
217 | 216 | settings = json.load(file_obj) |
218 | 217 | if not isinstance(settings, Mapping): |
219 | 218 | raise TypeError("The settings file must be a JSON object.") |
220 | | - validation_errors: dict[str, ValidationError] = {} |
221 | 219 | for name, value in settings: |
222 | 220 | try: |
223 | 221 | setting = self.settings[name] |
224 | 222 | # Load the key from the JSON file using the setting's model |
225 | 223 | model = setting.model.model_validate(value) |
226 | 224 | setting.set_without_emit_from_model(model) |
227 | | - except ValidationError as e: |
228 | | - validation_errors[name] = e |
| 225 | + except ValidationError: |
| 226 | + self.logger.warning( |
| 227 | + f"Could not load setting {name} from settings file " |
| 228 | + f"because of a validation error.", |
| 229 | + exc_info=True, |
| 230 | + ) |
229 | 231 | except KeyError: |
230 | 232 | self.logger.warning( |
231 | 233 | f"An extra key {name} was found in the settings file. " |
232 | 234 | "It will be deleted the next time settings are saved." |
233 | 235 | ) |
234 | | - if validation_errors: |
235 | | - # If one or more settings didn't validate, combine them into a single |
236 | | - # Pydantic validation error. |
237 | | - error_details: list[InitErrorDetails] = [] |
238 | | - for name, exc in validation_errors.items(): |
239 | | - for err in exc.errors(): |
240 | | - error_details.append( |
241 | | - { |
242 | | - "type": err["type"], |
243 | | - "loc": (name,) + err["loc"], |
244 | | - "input": err["input"], |
245 | | - "ctx": err["ctx"] if "ctx" in err else {}, |
246 | | - } |
247 | | - ) |
248 | | - raise ValidationError.from_exception_data( |
249 | | - "Some settings were not valid.", |
250 | | - error_details, |
251 | | - ) |
252 | 236 | except ( |
253 | 237 | FileNotFoundError, |
254 | 238 | JSONDecodeError, |
255 | 239 | PermissionError, |
256 | | - ValidationError, |
257 | 240 | TypeError, |
258 | 241 | ): |
259 | 242 | # Note that if the settings file is missing, we should already have returned |
260 | 243 | # before attempting to load settings. |
261 | 244 | self.logger.warning( |
262 | 245 | "Error loading settings for %s. " |
263 | | - "These settings will be reset to default.", |
| 246 | + "Settings for this Thing will be reset to default.", |
264 | 247 | thing_name, |
265 | 248 | ) |
266 | 249 | finally: |
|
0 commit comments