Skip to content

Commit

Permalink
refactor: Improve error handling when importing a module
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jun 19, 2023
1 parent 6da5869 commit a732e21
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/griffe/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ def dynamic_import(import_path: str, import_paths: list[Path] | None = None) ->
except ModuleNotFoundError as error:
if len(module_parts) == 1:
raise
errors.append(str(error))
errors.append(f"{error.__class__.__name__}: {error}")
object_parts.insert(0, module_parts.pop(-1))
except (Exception, BaseException) as error:
# pyo3's PanicException can only be caught with BaseException.
# We do want to catch base exceptions anyway (exit, interrupt, etc.),
errors.append(f"{error.__class__.__name__}: {error}")
raise ImportError("\n".join(errors)) from error
else:
break

Expand Down

0 comments on commit a732e21

Please sign in to comment.