From 0b5289d40fb3f88d40b14e757f5a8ef96a917ecc Mon Sep 17 00:00:00 2001 From: 5ila5 <5ila5@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:24:34 +0200 Subject: [PATCH] source shell improve error message when a import inside the source script fails old error message would also show source not found even though the import error is caused in the source not from importing the source --- .../waste_collection_schedule/source_shell.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source_shell.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source_shell.py index 4506a1747..08a0a7261 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source_shell.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source_shell.py @@ -217,8 +217,15 @@ def create( source_module: SourceModule = importlib.import_module( f"waste_collection_schedule.source.{source_name}" ) - except ImportError: - _LOGGER.error(f"source not found: {source_name}") + except ImportError as e: + if str(e).startswith( + f"No module named 'waste_collection_schedule.source.{source_name}'" + ): + _LOGGER.error(f"source not found: {source_name}") + else: + _LOGGER.error( + f"error loading source {source_name}:\n{e} \n{traceback.format_exc()}" + ) return None # create source