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