Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Core: Improve field construction exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mawildoer committed Sep 5, 2024
1 parent 1169587 commit e263abb
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/faebryk/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
logger = logging.getLogger(__name__)


# TODO: should this be a FaebrykException?
# TODO: should this include node and field information?
class FieldError(Exception):
pass

Expand Down Expand Up @@ -110,6 +112,13 @@ def __init__(self, node: "Node", *args: object) -> None:
self.node = node


class FieldConstructionError(FaebrykException):
def __init__(self, node: "Node", field: str, *args: object) -> None:
super().__init__(*args)
self.node = node
self.field = field


class NodeAlreadyBound(NodeException):
def __init__(self, node: "Node", other: "Node", *args: object) -> None:
super().__init__(
Expand Down Expand Up @@ -291,7 +300,7 @@ def append(name, inst):

return inst

def setup_field(name, obj):
def _setup_field(name, obj):
def setup_gen_alias(name, obj):
origin = get_origin(obj)
assert origin
Expand Down Expand Up @@ -321,6 +330,16 @@ def setup_gen_alias(name, obj):

raise NotImplementedError()

def setup_field(name, obj):
try:
_setup_field(name, obj)
except Exception as e:
raise FieldConstructionError(
self,
name,
f'An exception occurred while constructing field "{name}"',
) from e

nonrt, rt = partition(lambda x: isinstance(x[1], rt_field), clsfields.items())
for name, obj in nonrt:
setup_field(name, obj)
Expand Down

0 comments on commit e263abb

Please sign in to comment.