Skip to content

Commit

Permalink
fix: allow errors to propagate upwards
Browse files Browse the repository at this point in the history
Closes #187
  • Loading branch information
sombrek authored Oct 7, 2024
1 parent 7c7415b commit 9b607bd
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 6 deletions.
31 changes: 25 additions & 6 deletions lib/simulator/behaviors/EventBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,40 @@ EventBehaviors.prototype.get = function(element) {

'bpmn:ErrorEventDefinition': (context) => {

// HINT: errors are handled in current scope only (does not bubble)
// HINT: errors are propagated up the scope
// chain and caught by the first matching boundary event
// or event sub-process

const {
element,
scope
} = context;

const scopes = this._simulator.findScopes({
subscribedTo: {
event: element
},
trait: ScopeTraits.ACTIVE
});

let triggerScope = scope;

// TODO(nikku): ensure error always interrupts, also if no error
// catch is present
this._simulator.trigger({
event: element,
initiator: scope,
scope: findSubscriptionScope(scope)
});
while ((triggerScope = triggerScope.parent)) {

if (scopes.includes(triggerScope)) {
this._simulator.trigger({
event: element,
scope: triggerScope,
initiator: scope
});

break;
}
}
},

'bpmn:TerminateEventDefinition': (context) => {
const {
scope
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0e0nrgo" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.26.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:subProcess id="SubProcess">
<bpmn:incoming>Flow_1</bpmn:incoming>
<bpmn:outgoing>Flow_4</bpmn:outgoing>
<bpmn:startEvent id="StartEvent_2">
<bpmn:outgoing>Flow_2</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_2" sourceRef="StartEvent_2" targetRef="ErrorEvent_1" />
<bpmn:endEvent id="ErrorEvent_1" name="123">
<bpmn:incoming>Flow_2</bpmn:incoming>
<bpmn:errorEventDefinition id="ErrorEventDefinition_0wt6z4v" errorRef="Error_1d74h2e" />
</bpmn:endEvent>
</bpmn:subProcess>
<bpmn:sequenceFlow id="Flow_1" sourceRef="StartEvent_1" targetRef="SubProcess" />
<bpmn:endEvent id="EndEvent_2">
<bpmn:incoming>Flow_4</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_4" sourceRef="SubProcess" targetRef="EndEvent_2" />
<bpmn:subProcess id="EventSubProcess_3" triggeredByEvent="true">
<bpmn:endEvent id="EndEvent_5">
<bpmn:incoming>Flow_7</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_7" sourceRef="OuterErrorStart_none" targetRef="EndEvent_5" />
<bpmn:startEvent id="OuterErrorStart_none" name="&#60;none&#62;">
<bpmn:outgoing>Flow_7</bpmn:outgoing>
<bpmn:errorEventDefinition id="ErrorEventDefinition_059guvn" />
</bpmn:startEvent>
</bpmn:subProcess>
</bpmn:process>
<bpmn:error id="Error_1d74h2e" name="Error_123" errorCode="123" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="182" y="162" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0nq6a1j_di" bpmnElement="SubProcess" isExpanded="true">
<dc:Bounds x="275" y="80" width="520" height="390" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1r800jx_di" bpmnElement="StartEvent_2">
<dc:Bounds x="302" y="162" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0fqsq05_di" bpmnElement="ErrorEvent_1">
<dc:Bounds x="392" y="162" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="401" y="205" width="19" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0o271ah_di" bpmnElement="Flow_2">
<di:waypoint x="338" y="180" />
<di:waypoint x="392" y="180" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Event_0odig2x_di" bpmnElement="EndEvent_2">
<dc:Bounds x="852" y="162" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_06xdd3c" bpmnElement="EventSubProcess_3" isExpanded="true">
<dc:Bounds x="850" y="280" width="190" height="120" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_0u1gner" bpmnElement="EndEvent_5">
<dc:Bounds x="972" y="322" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1uv731i_di" bpmnElement="OuterErrorStart_none">
<dc:Bounds x="880" y="322" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="879" y="365" width="38" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_075k5pd" bpmnElement="Flow_7">
<di:waypoint x="916" y="340" />
<di:waypoint x="972" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1an8gzo_di" bpmnElement="Flow_1">
<di:waypoint x="218" y="180" />
<di:waypoint x="275" y="180" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ddz4nu_di" bpmnElement="Flow_4">
<di:waypoint x="795" y="180" />
<di:waypoint x="852" y="180" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
"createScope:Process_1:null",
"signal:Process_1:B",
"createScope:StartEvent_1:B",
"signal:StartEvent_1:C",
"exit:StartEvent_1:C",
"createScope:Flow_1:B",
"destroyScope:StartEvent_1:C",
"enter:Flow_1:B",
"exit:Flow_1:D",
"createScope:SubProcess:B",
"destroyScope:Flow_1:D",
"enter:SubProcess:B",
"createScope:StartEvent_2:E",
"signal:StartEvent_2:F",
"exit:StartEvent_2:F",
"createScope:Flow_2:E",
"destroyScope:StartEvent_2:F",
"enter:Flow_2:E",
"exit:Flow_2:G",
"createScope:ErrorEvent_1:E",
"destroyScope:Flow_2:G",
"enter:ErrorEvent_1:E",
"createScope:EventSubProcess_3:B",
"signal:EventSubProcess_3:I",
"destroyScope:ErrorEvent_1:H",
"destroyScope:SubProcess:E",
"createScope:OuterErrorStart_none:I",
"signal:OuterErrorStart_none:J",
"exit:OuterErrorStart_none:J",
"createScope:Flow_7:I",
"destroyScope:OuterErrorStart_none:J",
"enter:Flow_7:I",
"exit:Flow_7:K",
"createScope:EndEvent_5:I",
"destroyScope:Flow_7:K",
"enter:EndEvent_5:I",
"exit:EndEvent_5:L",
"destroyScope:EndEvent_5:L",
"exit:EventSubProcess_3:I",
"destroyScope:EventSubProcess_3:I",
"exit:Process_1:B",
"destroyScope:Process_1:B"
]
112 changes: 112 additions & 0 deletions test/spec/simulator/Simulator.error-catch-all-outer-event-sub-ref.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0e0nrgo" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.26.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:subProcess id="SubProcess">
<bpmn:incoming>Flow_1</bpmn:incoming>
<bpmn:outgoing>Flow_4</bpmn:outgoing>
<bpmn:startEvent id="StartEvent_2">
<bpmn:outgoing>Flow_2</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_2" sourceRef="StartEvent_2" targetRef="ErrorEvent_1" />
<bpmn:endEvent id="ErrorEvent_1" name="123">
<bpmn:incoming>Flow_2</bpmn:incoming>
<bpmn:errorEventDefinition id="ErrorEventDefinition_1ppkev3" errorRef="Error_1d74h2e" />
</bpmn:endEvent>
</bpmn:subProcess>
<bpmn:sequenceFlow id="Flow_1" sourceRef="StartEvent_1" targetRef="SubProcess" />
<bpmn:endEvent id="EndEvent_2">
<bpmn:incoming>Flow_4</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_4" sourceRef="SubProcess" targetRef="EndEvent_2" />
<bpmn:subProcess id="EventSubProcess_3" triggeredByEvent="true">
<bpmn:endEvent id="EndEvent_5">
<bpmn:incoming>Flow_7</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_7" sourceRef="OuterErrorStart_none" targetRef="EndEvent_5" />
<bpmn:startEvent id="OuterErrorStart_none" name="&#60;none&#62;">
<bpmn:outgoing>Flow_7</bpmn:outgoing>
<bpmn:errorEventDefinition id="ErrorEventDefinition_0eqytem" />
</bpmn:startEvent>
</bpmn:subProcess>
<bpmn:subProcess id="EventSubProcess_4" triggeredByEvent="true">
<bpmn:endEvent id="EndEvent_6">
<bpmn:incoming>Flow_8</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_8" sourceRef="OuterErrorStart_123" targetRef="EndEvent_6" />
<bpmn:startEvent id="OuterErrorStart_123" name="123">
<bpmn:outgoing>Flow_8</bpmn:outgoing>
<bpmn:errorEventDefinition id="ErrorEventDefinition_0wfxm7i" errorRef="Error_1d74h2e" />
</bpmn:startEvent>
</bpmn:subProcess>
</bpmn:process>
<bpmn:error id="Error_1d74h2e" name="Error_123" errorCode="123" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="182" y="162" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0nq6a1j_di" bpmnElement="SubProcess" isExpanded="true">
<dc:Bounds x="275" y="80" width="520" height="390" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1r800jx_di" bpmnElement="StartEvent_2">
<dc:Bounds x="302" y="162" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1lby0f4_di" bpmnElement="ErrorEvent_1">
<dc:Bounds x="392" y="162" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="401" y="205" width="19" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0o271ah_di" bpmnElement="Flow_2">
<di:waypoint x="338" y="180" />
<di:waypoint x="392" y="180" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Event_0odig2x_di" bpmnElement="EndEvent_2">
<dc:Bounds x="852" y="162" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_06xdd3c" bpmnElement="EventSubProcess_3" isExpanded="true">
<dc:Bounds x="850" y="280" width="190" height="120" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_0u1gner" bpmnElement="EndEvent_5">
<dc:Bounds x="972" y="322" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_03ii2yw_di" bpmnElement="OuterErrorStart_none">
<dc:Bounds x="880" y="322" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="879" y="365" width="38" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_075k5pd" bpmnElement="Flow_7">
<di:waypoint x="916" y="340" />
<di:waypoint x="972" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="BPMNShape_19s3z3r" bpmnElement="EventSubProcess_4" isExpanded="true">
<dc:Bounds x="1080" y="280" width="190" height="120" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_1ubj6u9" bpmnElement="EndEvent_6">
<dc:Bounds x="1202" y="322" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0eu7tni_di" bpmnElement="OuterErrorStart_123">
<dc:Bounds x="1110" y="322" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1119" y="365" width="19" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_0770paz" bpmnElement="Flow_8">
<di:waypoint x="1146" y="340" />
<di:waypoint x="1202" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1an8gzo_di" bpmnElement="Flow_1">
<di:waypoint x="218" y="180" />
<di:waypoint x="275" y="180" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ddz4nu_di" bpmnElement="Flow_4">
<di:waypoint x="795" y="180" />
<di:waypoint x="852" y="180" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
"createScope:Process_1:null",
"signal:Process_1:B",
"createScope:StartEvent_1:B",
"signal:StartEvent_1:C",
"exit:StartEvent_1:C",
"createScope:Flow_1:B",
"destroyScope:StartEvent_1:C",
"enter:Flow_1:B",
"exit:Flow_1:D",
"createScope:SubProcess:B",
"destroyScope:Flow_1:D",
"enter:SubProcess:B",
"createScope:StartEvent_2:E",
"signal:StartEvent_2:F",
"exit:StartEvent_2:F",
"createScope:Flow_2:E",
"destroyScope:StartEvent_2:F",
"enter:Flow_2:E",
"exit:Flow_2:G",
"createScope:ErrorEvent_1:E",
"destroyScope:Flow_2:G",
"enter:ErrorEvent_1:E",
"createScope:EventSubProcess_4:B",
"signal:EventSubProcess_4:I",
"destroyScope:ErrorEvent_1:H",
"destroyScope:SubProcess:E",
"createScope:OuterErrorStart_123:I",
"signal:OuterErrorStart_123:J",
"exit:OuterErrorStart_123:J",
"createScope:Flow_8:I",
"destroyScope:OuterErrorStart_123:J",
"enter:Flow_8:I",
"exit:Flow_8:K",
"createScope:EndEvent_6:I",
"destroyScope:Flow_8:K",
"enter:EndEvent_6:I",
"exit:EndEvent_6:L",
"destroyScope:EndEvent_6:L",
"exit:EventSubProcess_4:I",
"destroyScope:EventSubProcess_4:I",
"exit:Process_1:B",
"destroyScope:Process_1:B"
]
24 changes: 24 additions & 0 deletions test/spec/simulator/SimulatorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,30 @@ describe('simulator', function() {
expectTrace(fixture());
});


verify('escalation-catch-all-outer-event-sub-ref', (fixture) => {

// when
trigger({
element: element('StartEvent_1')
});

// then
expectTrace(fixture());
});


verify('escalation-catch-all-outer-event-sub-none', (fixture) => {

// when
trigger({
element: element('StartEvent_1')
});

// then
expectTrace(fixture());
});

});


Expand Down

0 comments on commit 9b607bd

Please sign in to comment.