Skip to content

Enhancement: Use "raise Exc from e" syntax when re-raising exceptions #462

@USSX-Hares

Description

@USSX-Hares

pdoc/pdoc/__init__.py

Lines 227 to 232 in f8704ec

try:
module = importlib.import_module(module_path)
except Exception as e:
msg = f'Error importing {module!r}: {e.__class__.__name__}: {e}'
if not skip_errors:
raise ImportError(msg)

Change raise ImportError(msg) to raise ImportError(msg) from e:

    try:
        module = importlib.import_module(module_path)
    except Exception as e:
        msg = f'Error importing {module!r}: {e.__class__.__name__}: {e}'
        if not skip_errors:
            raise ImportError(msg) from e

This improves exceptions readability.

I didn't search for other places in the repository, there're probably more places where raise x from y would be useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions