Skip to content

Commit

Permalink
print actual error message when failing to load a submodule (#2342)
Browse files Browse the repository at this point in the history
  • Loading branch information
kallewoof authored Jun 17, 2024
1 parent c013756 commit bc20262
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/huggingface_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc20262

Please sign in to comment.