Skip to content

Commit 98c6294

Browse files
authored
Merge pull request #287 from sartography/feature/workflow_data_exceptions
Workflow Data Exceptions were broken in the previous error refactor. …
2 parents a156378 + d40a1da commit 98c6294

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

SpiffWorkflow/bpmn/exceptions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
from SpiffWorkflow.exceptions import WorkflowException
1+
from SpiffWorkflow.exceptions import WorkflowTaskException
22

33

4-
class WorkflowDataException(WorkflowException):
4+
class WorkflowDataException(WorkflowTaskException):
55

6-
def __init__(self, task, data_input=None, data_output=None, message=None):
6+
def __init__(self, message, task, data_input=None, data_output=None):
77
"""
88
:param task: the task that generated the error
99
:param data_input: the spec of the input variable (if a data input)
1010
:param data_output: the spec of the output variable (if a data output)
1111
"""
12-
super().__init__(task.task_spec, message or 'data object error')
13-
self.task = task
12+
super().__init__(message, task)
1413
self.data_input = data_input
1514
self.data_output = data_output
16-
self.task_trace = self.get_task_trace(task)

SpiffWorkflow/bpmn/specs/BpmnProcessSpec.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,30 @@ def __init__(self, name, description=None):
7272
def get(self, my_task):
7373
"""Copy a value form the workflow data to the task data."""
7474
if self.name not in my_task.workflow.data:
75-
message = f"Workflow variable {self.name} not found"
76-
raise WorkflowDataException(my_task, data_input=self, message=message)
75+
message = f"Data object '{self.name}' " \
76+
f"does not exist and can not be read."
77+
raise WorkflowDataException(message, my_task, data_input=self)
7778
my_task.data[self.name] = deepcopy(my_task.workflow.data[self.name])
7879

7980
def set(self, my_task):
8081
"""Copy a value from the task data to the workflow data"""
8182
if self.name not in my_task.data:
82-
message = f"Task variable {self.name} not found"
83-
raise WorkflowDataException(my_task, data_output=self, message=message)
83+
message = f"A Data Object '{self.name}' " \
84+
f"could not be set, it does not exist in the task data"
85+
raise WorkflowDataException(message, my_task, data_output=self)
8486
my_task.workflow.data[self.name] = deepcopy(my_task.data[self.name])
8587
del my_task.data[self.name]
8688
data_log.info(f'Set workflow variable {self.name}', extra=my_task.log_info())
8789

8890
def copy(self, source, destination, data_input=False, data_output=False):
8991
"""Copy a value from one task to another."""
9092
if self.name not in source.data:
91-
message = f"Unable to copy {self.name}"
93+
message = f"'{self.name}' was not found in the task data"
9294
raise WorkflowDataException(
93-
source,
95+
message,
96+
source,
9497
data_input=self if data_input else None,
9598
data_output=self if data_output else None,
96-
message=message
9799
)
98100
destination.data[self.name] = deepcopy(source.data[self.name])
99101

SpiffWorkflow/bpmn/specs/SubWorkflowTask.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from SpiffWorkflow.task import TaskState
55
from .BpmnSpecMixin import BpmnSpecMixin
6+
from ..exceptions import WorkflowDataException
67
from ...specs.base import TaskSpec
78

89

@@ -51,7 +52,11 @@ def _on_subworkflow_completed(self, subworkflow, my_task):
5152
end = subworkflow.get_tasks_from_spec_name('End', workflow=subworkflow)
5253
# Otherwise only copy data with the specified names
5354
for var in subworkflow.spec.data_outputs:
54-
var.copy(end[0], my_task, data_output=True)
55+
try:
56+
var.copy(end[0], my_task, data_output=True)
57+
except WorkflowDataException as wde:
58+
wde.add_note("A Data Output was not provided as promised.")
59+
raise wde
5560

5661
my_task._set_state(TaskState.READY)
5762

@@ -83,8 +88,11 @@ def start_workflow(self, my_task):
8388
else:
8489
# Otherwise copy only task data with the specified names
8590
for var in subworkflow.spec.data_inputs:
86-
var.copy(my_task, start[0], data_input=True)
87-
91+
try:
92+
var.copy(my_task, start[0], data_input=True)
93+
except WorkflowDataException as wde:
94+
wde.add_note("You are missing a required Data Input for a call activity.")
95+
raise wde
8896
for child in subworkflow.task_tree.children:
8997
child.task_spec._update(child)
9098

tests/SpiffWorkflow/bpmn/IOSpecTest.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ def testCallActivityWithIOSpecSaveRestore(self):
1818
self.actual_test(True)
1919

2020
def testCallActivityMissingInput(self):
21-
21+
2222
self.workflow = BpmnWorkflow(self.spec, self.subprocesses)
2323
set_data = self.workflow.spec.task_specs['Activity_0haob58']
2424
set_data.script = """in_1, unused = 1, True"""
2525

2626
with self.assertRaises(WorkflowDataException) as exc:
2727
self.advance_to_subprocess()
28-
self.assertEqual(exc.var.name,'in_2')
28+
self.assertEqual("'in_2' was not found in the task data. "
29+
"You are missing a required Data Input for a call activity.",
30+
str(exc.exception))
31+
self.assertEqual(exc.exception.data_input.name,'in_2')
2932

3033
def testCallActivityMissingOutput(self):
3134

@@ -40,7 +43,10 @@ def testCallActivityMissingOutput(self):
4043

4144
with self.assertRaises(WorkflowDataException) as exc:
4245
self.complete_subprocess()
43-
self.assertEqual(exc.var.name,'out_2')
46+
47+
self.assertEqual("'out_2' was not found in the task data. A Data Output was not provided as promised.",
48+
str(exc.exception))
49+
self.assertEqual(exc.exception.data_output.name,'out_2')
4450

4551
def actual_test(self, save_restore=False):
4652

@@ -85,4 +91,4 @@ def complete_subprocess(self):
8591
while len(waiting) > 0:
8692
next_task = self.workflow.get_tasks(TaskState.READY)[0]
8793
next_task.complete()
88-
waiting = self.workflow.get_tasks(TaskState.WAITING)
94+
waiting = self.workflow.get_tasks(TaskState.WAITING)

0 commit comments

Comments
 (0)