Skip to content

Commit

Permalink
Merge pull request #637 from pfebrer/clearer_node_errors
Browse files Browse the repository at this point in the history
Optionally avoid custom node errors.
  • Loading branch information
zerothi authored Nov 1, 2023
2 parents bea0161 + 1002a5e commit 89dcede
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/sisl/nodes/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
# On initialization, should the node compute? If None, defaults to `lazy`.
lazy_init=None,
# The level of logs stored in the node.
log_level="INFO"
log_level="INFO",
# Whether to raise a custom error exception (e.g. NodeCalcError) By default
# it is turned off because it can obscure the real problem by not showing it
# in the last traceback frame.
raise_custom_errors=False,
)

# Temporal contexts stack. It should not be used directly by users, the aim of this
Expand Down
11 changes: 10 additions & 1 deletion src/sisl/nodes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class Node(NDArrayOperatorsMixin):
# Whether the node has errored during the last execution
# with the current inputs.
_errored: bool
# The error that was raised during the last execution
_error: Optional[NodeError] = None

# Logs of the node's execution.
_logger: logging.Logger
Expand Down Expand Up @@ -133,6 +135,7 @@ def setup(self, *args, **kwargs):

self._outdated = True
self._errored = False
self._error = None

self._logger = logging.getLogger(
str(id(self))
Expand Down Expand Up @@ -370,12 +373,18 @@ def get(self):
self.logs += logs.stream.getvalue()
logs.close()
self._errored = True
raise NodeCalcError(self, e, evaluated_inputs)
self._error = NodeCalcError(self, e, evaluated_inputs)

if self.context['raise_custom_errors']:
raise self._error
else:
raise e

self._nupdates += 1
self._prev_evaluated_inputs = evaluated_inputs
self._outdated = False
self._errored = False
self._error = None
else:
self._logger.info(f"No need to evaluate")

Expand Down

0 comments on commit 89dcede

Please sign in to comment.