From bc2026238ca03d5a8eea12878265714b16371f13 Mon Sep 17 00:00:00 2001 From: kallewoof Date: Mon, 17 Jun 2024 16:27:38 +0900 Subject: [PATCH] print actual error message when failing to load a submodule (#2342) --- src/huggingface_hub/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/huggingface_hub/__init__.py b/src/huggingface_hub/__init__.py index 41d64f9f1b..0b692f5b01 100644 --- a/src/huggingface_hub/__init__.py +++ b/src/huggingface_hub/__init__.py @@ -503,10 +503,18 @@ def _attach(package_name, submodules=None, submod_attrs=None): def __getattr__(name): if name in submodules: - return importlib.import_module(f"{package_name}.{name}") + try: + return importlib.import_module(f"{package_name}.{name}") + except Exception as e: + print(f"Error importing {package_name}.{name}: {e}") + raise elif name in attr_to_modules: submod_path = f"{package_name}.{attr_to_modules[name]}" - submod = importlib.import_module(submod_path) + try: + submod = importlib.import_module(submod_path) + except Exception as e: + print(f"Error importing {submod_path}: {e}") + raise attr = getattr(submod, name) # If the attribute lives in a file (module) with the same