Skip to content

Commit 614bc60

Browse files
committed
rework mhkit init error messages
1 parent 6125357 commit 614bc60

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

mhkit/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ def __getattr__(name):
3737
]
3838

3939
if name in known_modules:
40-
return importlib.import_module(f"mhkit.{name}")
41-
42-
if name in known_modules:
43-
error_msg = f"\n\nTo install the {name} module, run:\n"
44-
error_msg += f"pip install mhkit[{name}]\n\n"
45-
error_msg += "Or install all modules with:\n"
46-
error_msg += "pip install mhkit[all]"
40+
try:
41+
return importlib.import_module(f"mhkit.{name}")
42+
except ModuleNotFoundError:
43+
error_msg = "Module dependencies not found.\n"
44+
error_msg += f"To install the {name} module, run:\n"
45+
error_msg += f" pip install mhkit[{name}]\n\n"
46+
error_msg += "Or install all modules with:\n"
47+
error_msg += " pip install mhkit[all]"
4748
else:
4849
error_msg = f"module 'mhkit' has no attribute '{name}'"
4950

0 commit comments

Comments
 (0)