Moved config check into find_metadata_source_plugins func.

This commit is contained in:
Sebastian Mohr 2025-11-10 18:33:52 +01:00
parent 2951f38fe5
commit a69f575b90
2 changed files with 13 additions and 5 deletions

View file

@ -46,7 +46,13 @@ log = logging.getLogger("beets")
def find_metadata_source_plugins() -> list[MetadataSourcePlugin]: def find_metadata_source_plugins() -> list[MetadataSourcePlugin]:
"""Return a list of all loaded metadata source plugins.""" """Return a list of all loaded metadata source plugins."""
# TODO: Make this an isinstance(MetadataSourcePlugin, ...) check in v3.0.0 # TODO: Make this an isinstance(MetadataSourcePlugin, ...) check in v3.0.0
return [SafeProxy(p) for p in find_plugins() if hasattr(p, "data_source")] # type: ignore[misc,arg-type] # This should also allow us to remove the type: ignore comments below.
metadata_plugins = [p for p in find_plugins() if hasattr(p, "data_source")]
if config["raise_on_error"].get(bool):
return metadata_plugins # type: ignore[return-value]
else:
return list(map(SafeProxy, metadata_plugins)) # type: ignore[arg-type]
@notify_info_yielded("albuminfo_received") @notify_info_yielded("albuminfo_received")
@ -419,8 +425,6 @@ class SafeProxy(base):
def __handle_exception(self, func: Callable[P, R], e: Exception) -> None: def __handle_exception(self, func: Callable[P, R], e: Exception) -> None:
"""Helper function to log exceptions from metadata source plugins.""" """Helper function to log exceptions from metadata source plugins."""
if config["raise_on_error"].get(bool):
raise e
log.error( log.error(
"Error in '{}.{}': {}", "Error in '{}.{}': {}",
self.__plugin.data_source, self.__plugin.data_source,
@ -435,9 +439,9 @@ class SafeProxy(base):
except Exception as e: except Exception as e:
return self.__handle_exception(self.__plugin.album_for_id, e) return self.__handle_exception(self.__plugin.album_for_id, e)
def track_for_id(self, track_id: str): def track_for_id(self, *args, **kwargs):
try: try:
return self.__plugin.track_for_id(track_id) return self.__plugin.track_for_id(*args, **kwargs)
except Exception as e: except Exception as e:
return self.__handle_exception(self.__plugin.track_for_id, e) return self.__handle_exception(self.__plugin.track_for_id, e)

View file

@ -33,6 +33,10 @@ Bug fixes:
the default config path. :bug:`5652` the default config path. :bug:`5652`
- :doc:`plugins/lyrics`: Accepts strings for lyrics sources (previously only - :doc:`plugins/lyrics`: Accepts strings for lyrics sources (previously only
accepted a list of strings). :bug:`5962` accepted a list of strings). :bug:`5962`
- Errors in metadata plugins during autotage process will now be logged but
won't crash beets anymore. If you want to raise exceptions instead, set the
new configuration option ``raise_on_error`` to ``yes`` :bug:`5903`,
:bug:`4789`.
For plugin developers: For plugin developers: