Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally avoid custom node errors. #637

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -41,7 +41,7 @@
# Should make this more specific
return (f"Some input is not right in {self._node} and could not be parsed")

class Node(NDArrayOperatorsMixin):

Check warning

Code scanning / CodeQL

`__eq__` not overridden when adding attributes Warning

The class 'Node' does not override
'__eq__'
, but adds the new attribute
_inputs
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_input_nodes
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_output_links
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_prev_evaluated_inputs
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_output
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_nupdates
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_outdated
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_errored
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_error
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_logger
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_log_formatter
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
logs
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
context
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_cls_context
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
context
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_known_function_nodes
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
__doc__
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_args_inputs_key
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_kwargs_inputs_key
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_args_inputs_key
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_kwargs_inputs_key
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
__signature__
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_output
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_errored
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_error
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_prev_evaluated_inputs
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_outdated
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_errored
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_error
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_outdated
.
The class 'Node' does not override
'__eq__'
, but adds the new attribute
_errored
.
"""Generic class for nodes.

A node is a process that runs with some inputs and returns some outputs.
Expand Down Expand Up @@ -90,6 +90,8 @@
# 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 @@

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

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

Check warning on line 376 in src/sisl/nodes/node.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/nodes/node.py#L376

Added line #L376 was not covered by tests

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

Check warning on line 379 in src/sisl/nodes/node.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/nodes/node.py#L378-L379

Added lines #L378 - L379 were not covered by tests
else:
raise e

Check warning on line 381 in src/sisl/nodes/node.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/nodes/node.py#L381

Added line #L381 was not covered by tests

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
Loading