Coverage for src/_griffe/exceptions.py: 89.66%
29 statements
« prev ^ index » next coverage.py v7.6.2, created at 2024-10-12 01:34 +0200
« prev ^ index » next coverage.py v7.6.2, created at 2024-10-12 01:34 +0200
1# This module contains all the exceptions specific to Griffe.
3from __future__ import annotations
5from typing import TYPE_CHECKING
7if TYPE_CHECKING:
8 from _griffe.models import Alias
11class GriffeError(Exception):
12 """The base exception for all Griffe errors."""
15class LoadingError(GriffeError):
16 """The base exception for all Griffe errors."""
19class NameResolutionError(GriffeError):
20 """Exception for names that cannot be resolved in a object scope."""
23class UnhandledEditableModuleError(GriffeError):
24 """Exception for unhandled editables modules, when searching modules."""
27class UnimportableModuleError(GriffeError):
28 """Exception for modules that cannot be imported."""
31class AliasResolutionError(GriffeError):
32 """Exception for alias that cannot be resolved."""
34 def __init__(self, alias: Alias) -> None:
35 """Initialize the exception.
37 Parameters:
38 alias: The alias that could not be resolved.
39 """
40 self.alias: Alias = alias
41 """The alias that triggered the error."""
43 message = f"Could not resolve alias {alias.path} pointing at {alias.target_path}"
44 try:
45 filepath = alias.parent.relative_filepath # type: ignore[union-attr]
46 except BuiltinModuleError:
47 pass
48 else:
49 message += f" (in {filepath}:{alias.alias_lineno})"
50 super().__init__(message)
53class CyclicAliasError(GriffeError):
54 """Exception raised when a cycle is detected in aliases."""
56 def __init__(self, chain: list[str]) -> None:
57 """Initialize the exception.
59 Parameters:
60 chain: The cyclic chain of items (such as target path).
61 """
62 self.chain: list[str] = chain
63 """The chain of aliases that created the cycle."""
65 super().__init__("Cyclic aliases detected:\n " + "\n ".join(self.chain))
68class LastNodeError(GriffeError):
69 """Exception raised when trying to access a next or previous node."""
72class RootNodeError(GriffeError):
73 """Exception raised when trying to use siblings properties on a root node."""
76class BuiltinModuleError(GriffeError):
77 """Exception raised when trying to access the filepath of a builtin module."""
80class ExtensionError(GriffeError):
81 """Base class for errors raised by extensions."""
84class ExtensionNotLoadedError(ExtensionError):
85 """Exception raised when an extension could not be loaded."""
88class GitError(GriffeError):
89 """Exception raised for errors related to Git."""