Skip to content

Commit

Permalink
👌 IMPROVE: Add 'exception' to projection mapping (#4786)
Browse files Browse the repository at this point in the history
This commit adds `exception` to the list of allowed projections,
and also standardises the way the exception is set on the node
(capturing both the type and message).
  • Loading branch information
chrisjsewell authored Mar 3, 2021
1 parent 6044d81 commit a244618
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion aiida/cmdline/utils/query/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class CalculationQueryBuilder:
_default_projections = ('pk', 'ctime', 'process_label', 'state', 'process_status')
_valid_projections = (
'pk', 'uuid', 'ctime', 'mtime', 'state', 'process_state', 'process_status', 'exit_status', 'sealed',
'process_label', 'label', 'description', 'node_type', 'paused', 'process_type', 'job_state', 'scheduler_state'
'process_label', 'label', 'description', 'node_type', 'paused', 'process_type', 'job_state', 'scheduler_state',
'exception'
)

def __init__(self, mapper=None):
Expand Down
2 changes: 2 additions & 0 deletions aiida/cmdline/utils/query/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, projections, projection_labels=None, projection_attributes=No
process_state_key = f'attributes.{ProcessNode.PROCESS_STATE_KEY}'
process_status_key = f'attributes.{ProcessNode.PROCESS_STATUS_KEY}'
exit_status_key = f'attributes.{ProcessNode.EXIT_STATUS_KEY}'
exception_key = f'attributes.{ProcessNode.EXCEPTION_KEY}'

default_labels = {'pk': 'PK', 'uuid': 'UUID', 'ctime': 'Created', 'mtime': 'Modified', 'state': 'Process State'}

Expand All @@ -104,6 +105,7 @@ def __init__(self, projections, projection_labels=None, projection_attributes=No
'process_state': process_state_key,
'process_status': process_status_key,
'exit_status': exit_status_key,
'exception': exception_key,
}

default_formatters = {
Expand Down
2 changes: 1 addition & 1 deletion aiida/engine/processes/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def on_except(self, exc_info: Tuple[Any, Exception, TracebackType]) -> None:
:param exc_info: the sys.exc_info() object (type, value, traceback)
"""
super().on_except(exc_info)
self.node.set_exception(''.join(traceback.format_exception(exc_info[0], exc_info[1], None)))
self.node.set_exception(''.join(traceback.format_exception(exc_info[0], exc_info[1], None)).rstrip())
self.report(''.join(traceback.format_exception(*exc_info)))

@override
Expand Down
3 changes: 2 additions & 1 deletion aiida/manage/external/rmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""Components to communicate tasks to RabbitMQ."""
from collections.abc import Mapping
import logging
import traceback

from kiwipy import communications, Future
import pamqp.encode
Expand Down Expand Up @@ -154,7 +155,7 @@ def handle_continue_exception(node, exception, message):

if not node.is_excepted and not node.is_sealed:
node.logger.exception(message)
node.set_exception(str(exception))
node.set_exception(''.join(traceback.format_exception(type(exception), exception, None)).rstrip())
node.set_process_state(ProcessState.EXCEPTED)
node.seal()

Expand Down

0 comments on commit a244618

Please sign in to comment.