🎨 Work on import error handling

- Generic ErrorProducer class
- Importer and managers are error producers
- SGDB Auth friendly error
- Bad source location friendly errors (data, config, cache)
- Removed unused decorators
This commit is contained in:
GeoffreyCoulaud
2023-06-24 15:13:35 +02:00
parent 41c2a1023a
commit 3fa80a53c6
10 changed files with 136 additions and 100 deletions

View File

@@ -20,10 +20,11 @@
import sys
from abc import abstractmethod
from collections.abc import Iterable, Iterator
from typing import Generator, Any, Optional
from typing import Any, Generator, Optional
from src.importer.sources.location import Location
from src.errors.friendly_error import FriendlyError
from src.game import Game
from src.importer.sources.location import Location, UnresolvableLocationError
# Type of the data returned by iterating on a Source
SourceIterationResult = None | Game | tuple[Game, tuple[Any]]
@@ -100,9 +101,20 @@ class Source(Iterable):
def __iter__(self) -> SourceIterator:
"""Get an iterator for the source"""
for location in (self.data_location, self.cache_location, self.config_location):
if location is not None:
for location_name in ("data", "cache", "config"):
location = getattr(self, f"{location_name}_location", None)
if location is None:
continue
try:
location.resolve()
except UnresolvableLocationError as error:
raise FriendlyError(
# The variable is the source's name
f"Invalid {location_name} location for {{}}",
"Change it or disable the source in the preferences",
(self.name,),
(self.name,),
) from error
return self.iterator_class(self)