Skip to content

Commit

Permalink
refactor: Reorganize exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Nov 20, 2021
1 parent dd8522c commit 7f9b805
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/griffe/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from griffe.collections import lines_collection
from griffe.docstrings.dataclasses import DocstringSection
from griffe.docstrings.parsers import Parser, parse # noqa: WPS347
from griffe.exceptions import ResolutionError
from griffe.exceptions import NameResolutionError
from griffe.expressions import Expression, Name


Expand Down Expand Up @@ -477,7 +477,7 @@ def resolve(self, name: str) -> str:
name: The name to resolve.
Raises:
ResolutionError: When the name could not be resolved.
NameResolutionError: When the name could not be resolved.
Returns:
The resolved name.
Expand All @@ -488,7 +488,7 @@ def resolve(self, name: str) -> str:
return self.imports[name]
if self.parent is None:
# could be a built-in
raise ResolutionError(f"{name} could not be resolved in the scope of {self.path}")
raise NameResolutionError(f"{name} could not be resolved in the scope of {self.path}")
if name == self.parent.name:
return self.parent.path
return self.parent.resolve(name)
Expand Down
16 changes: 14 additions & 2 deletions src/griffe/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
"""This module contains all the exceptions specific to Griffe."""


class ResolutionError(Exception):
class GriffeError(Exception):
"""The base exception for all Griffe errors."""


class NameResolutionError(GriffeError):
"""Exception for names that cannot be resolved in a object scope."""


class UnhandledPthFileError(Exception):
class UnhandledPthFileError(GriffeError):
"""Exception for unhandled .path files, when searching modules."""


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."""
4 changes: 2 additions & 2 deletions src/griffe/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import Any, Callable

from griffe.exceptions import ResolutionError
from griffe.exceptions import NameResolutionError


class Name:
Expand Down Expand Up @@ -49,7 +49,7 @@ def full(self) -> str:
if not self._full:
try:
self._full = self._resolver() or self.source
except ResolutionError:
except NameResolutionError:
# probably a built-in
self._full = self.source
return self._full
Expand Down
8 changes: 1 addition & 7 deletions src/griffe/extended_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@
from ast import AST # noqa: WPS458
from functools import cached_property


class LastNodeError(Exception):
"""Exception raised when trying to access a next or previous node."""


class RootNodeError(Exception):
"""Exception raised when trying to use siblings properties on a root node."""
from griffe.exceptions import LastNodeError, RootNodeError


class _ExtendedAST:
Expand Down

0 comments on commit 7f9b805

Please sign in to comment.