Skip to content

Commit

Permalink
Adapt exit() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mbercx committed May 10, 2023
1 parent b3655a9 commit 6529ea6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/aiida_quantumespresso/parsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def emit_logs(self, logs: AttributeDict, ignore: list = None) -> None:
continue

try:
getattr(self.logger, level)(stripped)
self.logger.log(level, stripped)
except AttributeError:
pass

Expand Down Expand Up @@ -141,18 +141,30 @@ def check_base_errors(self, logs: AttributeDict) -> Optional[ExitCode]:
exception = logs.error[logs.index(exit_code) + 1]
return self.exit_codes.get(exit_code).format(exception=exception)

def exit(self, exit_code: ExitCode, logs: AttributeDict = None) -> ExitCode:
"""Log the exit message of the give exit code with level `ERROR` and return the exit code.
def exit(self, logs: AttributeDict = None, exit_code: ExitCode = None) -> ExitCode:
"""Log all messages in the ``logs`` as well as the ``exit_code`` message and return the correct exit code.
This is a utility function if one wants to return from the parse method and automically add the exit message
associated to the exit code as a log message to the node: e.g. ``return self._exit(self.exit_codes.LABEL))``
This is a utility function if one wants to return from the parse method and automically add the ``logs`` and
exit message associated to and exit code as a log message to the node: e.g.
``return self._exit(self.exit_codes.LABEL))``
:param exit_code: an `ExitCode`
:return: the exit code
If no ``exit_code`` is provided, the method will check if an ``exit_status`` has already been set on the node
and return the corresponding ``ExitCode`` in this case. If not, ``ExitCode(0)`` is returned.
:param logs: log dictionaries
:param exit_code: an ``ExitCode``
:return: The correct exit code
"""
if logs:
self.emit_logs(logs)
self.logger.error(exit_code.message)

if exit_code is not None:
self.logger.error(exit_code.message)
elif self.node.exit_status is not None:
exit_code = ExitCode(self.node.exit_status, self.node.exit_message)
else:
exit_code = ExitCode(0)

return exit_code

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions src/aiida_quantumespresso/parsers/open_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def parse(self, **kwargs):
if exit_code in logs.error:
return self.exit(self.exit_codes.get(exit_code), logs)

return self.exit(logs)

@staticmethod
def parse_kpoints(stdout: str, logs: AttributeDict) -> Tuple[KpointsData, KpointsData, AttributeDict]:
"""Parse the ``stdout`` for the mesh and explicit list of kpoints."""
Expand Down

0 comments on commit 6529ea6

Please sign in to comment.