Merge pull request #122 from kra-mo/fix-bad-source-location-error

Silently skip sources with bad locations
This commit is contained in:
kramo
2023-06-30 13:37:01 +02:00
committed by GitHub
2 changed files with 16 additions and 26 deletions

View File

@@ -26,6 +26,7 @@ from src import shared
from src.errors.error_producer import ErrorProducer from src.errors.error_producer import ErrorProducer
from src.errors.friendly_error import FriendlyError from src.errors.friendly_error import FriendlyError
from src.game import Game from src.game import Game
from src.importer.sources.location import UnresolvableLocationError
from src.importer.sources.source import Source from src.importer.sources.source import Source
from src.store.managers.async_manager import AsyncManager from src.store.managers.async_manager import AsyncManager
from src.store.pipeline import Pipeline from src.store.pipeline import Pipeline
@@ -125,16 +126,18 @@ class Importer(ErrorProducer):
source: Source source: Source
source, *_rest = data source, *_rest = data
# Early exit if not installed # Early exit if not available or not installed
if not source.is_available: if not source.is_available:
logging.info("Source %s skipped, not installed", source.id) logging.info("Source %s skipped, not available", source.id)
return
try:
iterator = iter(source)
except UnresolvableLocationError:
logging.info("Source %s skipped, bad location", source.id)
return return
logging.info("Scanning source %s", source.id)
# Initialize source iteration
iterator = iter(source)
# Get games from source # Get games from source
logging.info("Scanning source %s", source.id)
while True: while True:
# Handle exceptions raised when iterating # Handle exceptions raised when iterating
try: try:

View File

@@ -22,9 +22,8 @@ from abc import abstractmethod
from collections.abc import Iterable, Iterator from collections.abc import Iterable, Iterator
from typing import Any, Generator, Optional from typing import Any, Generator, Optional
from src.errors.friendly_error import FriendlyError
from src.game import Game from src.game import Game
from src.importer.sources.location import Location, UnresolvableLocationError from src.importer.sources.location import Location
# Type of the data returned by iterating on a Source # Type of the data returned by iterating on a Source
SourceIterationResult = None | Game | tuple[Game, tuple[Any]] SourceIterationResult = None | Game | tuple[Game, tuple[Any]]
@@ -100,27 +99,15 @@ class Source(Iterable):
"""The executable format used to construct game executables""" """The executable format used to construct game executables"""
def __iter__(self) -> SourceIterator: def __iter__(self) -> SourceIterator:
"""Get an iterator for the source""" """
for location_name in ( Get an iterator for the source
locations := { :raises UnresolvableLocationError: Not iterable if any of the locations are unresolvable
"data": "Data", """
"cache": "Cache", for location_name in ("data", "cache", "config"):
"config": "Configuration",
}.keys()
):
location = getattr(self, f"{location_name}_location", None) location = getattr(self, f"{location_name}_location", None)
if location is None: if location is None:
continue continue
try: location.resolve()
location.resolve()
except UnresolvableLocationError as error:
raise FriendlyError(
# The variables are the type of location (eg. cache) and the source's name (eg. Steam)
"Invalid {} Location for {{}}".format(locations[location_name]),
"Pick a new one or disable the source in preferences",
(self.name,),
(self.name,),
) from error
return self.iterator_class(self) return self.iterator_class(self)