| 1 |
|
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from typing import TYPE_CHECKING |
| 6 |
|
| 7 |
if TYPE_CHECKING: |
| 8 |
from griffe._internal.models import Alias |
| 9 |
|
| 10 |
|
| 11 |
class GriffeError(Exception): |
| 12 |
"""The base exception for all Griffe errors.""" |
| 13 |
|
| 14 |
|
| 15 |
class LoadingError(GriffeError): |
| 16 |
"""The base exception for all Griffe errors.""" |
| 17 |
|
| 18 |
|
| 19 |
class NameResolutionError(GriffeError): |
| 20 |
"""Exception for names that cannot be resolved in a object scope.""" |
| 21 |
|
| 22 |
|
| 23 |
class UnhandledEditableModuleError(GriffeError): |
| 24 |
"""Exception for unhandled editables modules, when searching modules.""" |
| 25 |
|
| 26 |
|
| 27 |
class UnimportableModuleError(GriffeError): |
| 28 |
"""Exception for modules that cannot be imported.""" |
| 29 |
|
| 30 |
|
| 31 |
class AliasResolutionError(GriffeError): |
| 32 |
"""Exception for alias that cannot be resolved.""" |
| 33 |
|
| 34 |
def __init__(self, alias: Alias) -> None: |
| 35 |
"""Initialize the exception. |
| 36 |
|
| 37 |
Parameters: |
| 38 |
alias: The alias that could not be resolved. |
| 39 |
""" |
| 40 |
self.alias: Alias = alias |
| 41 |
"""The alias that triggered the error.""" |
| 42 |
|
| 43 |
message = f"Could not resolve alias {alias.path} pointing at {alias.target_path}" |
| 44 |
try: |
| 45 |
filepath = alias.parent.relative_filepath |
| 46 |
except BuiltinModuleError: |
| 47 |
pass |
| 48 |
else: |
| 49 |
message += f" (in {filepath}:{alias.alias_lineno})" |
| 50 |
super().__init__(message) |
| 51 |
|
| 52 |
|
| 53 |
class CyclicAliasError(GriffeError): |
| 54 |
"""Exception raised when a cycle is detected in aliases.""" |
| 55 |
|
| 56 |
def __init__(self, chain: list[str]) -> None: |
| 57 |
"""Initialize the exception. |
| 58 |
|
| 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.""" |
| 64 |
|
| 65 |
super().__init__("Cyclic aliases detected:\n " + "\n ".join(self.chain)) |
| 66 |
|
| 67 |
|
| 68 |
class LastNodeError(GriffeError): |
| 69 |
"""Exception raised when trying to access a next or previous node.""" |
| 70 |
|
| 71 |
|
| 72 |
class RootNodeError(GriffeError): |
| 73 |
"""Exception raised when trying to use siblings properties on a root node.""" |
| 74 |
|
| 75 |
|
| 76 |
class BuiltinModuleError(GriffeError): |
| 77 |
"""Exception raised when trying to access the filepath of a builtin module.""" |
| 78 |
|
| 79 |
|
| 80 |
class ExtensionError(GriffeError): |
| 81 |
"""Base class for errors raised by extensions.""" |
| 82 |
|
| 83 |
|
| 84 |
class ExtensionNotLoadedError(ExtensionError): |
| 85 |
"""Exception raised when an extension could not be loaded.""" |
| 86 |
|
| 87 |
|
| 88 |
class GitError(GriffeError): |
| 89 |
"""Exception raised for errors related to Git.""" |