BpmnError thrown from Output parameter does not get catch in Error boundary condition


#1

I need to handle error conditions in Output Parameter of Script Task. When there is any error in preparing output parameter, I want to terminate the flow the go to Error Boundary condition but it is not getting control and flow is terminating abruptly. Please suggest.
I can probably catch all errors in Output Parameter section and return some dummy value to Output Parameter and then put condition outside of the Script Task to terminate the flow. But its multi step process. What is the best way to handle this?

Here is my BPMN

<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.8.0">
  <bpmn:process id="PM_DUMMY_WORKFLOW" name="PM Dummy Workflow Error" isExecutable="true">
    <bpmn:extensionElements>
      <camunda:executionListener event="end">
        <camunda:script scriptFormat="groovy"><![CDATA[println "PM Dummy workflow completed"]]></camunda:script>
      </camunda:executionListener>
    </bpmn:extensionElements>
    <bpmn:laneSet />
    <bpmn:startEvent id="START_EVENT" name="Start" camunda:asyncBefore="true" camunda:exclusive="false">
      <bpmn:outgoing>SequenceFlow_0lld5pj</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="SequenceFlow_0lld5pj" sourceRef="START_EVENT" targetRef="Wait_Task" />
    <bpmn:scriptTask id="Wait_Task" name="Wait Task" camunda:asyncBefore="true" camunda:asyncAfter="true" scriptFormat="groovy">
      <bpmn:extensionElements>
        <camunda:inputOutput>
          <camunda:outputParameter name="Script_Task_Output_Param">
            <camunda:script scriptFormat="groovy"><![CDATA[
import org.camunda.bpm.engine.delegate.BpmnError;
println "Executing output parameter script for the task";
throw new BpmnError("OUT_PARAM_100", "Error in output parameter");
]]></camunda:script>
          </camunda:outputParameter>
        </camunda:inputOutput>
      </bpmn:extensionElements>
      <bpmn:incoming>SequenceFlow_0lld5pj</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1eckowf</bpmn:outgoing>
      <bpmn:script><![CDATA[println "Test script";
]]></bpmn:script>
    </bpmn:scriptTask>
    <bpmn:endEvent id="END_EVENT" name="End">
      <bpmn:incoming>SequenceFlow_1eckowf</bpmn:incoming>
      <bpmn:incoming>SequenceFlow_1ckp4p8</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="SequenceFlow_1eckowf" sourceRef="Wait_Task" targetRef="END_EVENT" />
    <bpmn:boundaryEvent id="BoundaryEvent_0zugk5b" attachedToRef="Wait_Task">
      <bpmn:outgoing>SequenceFlow_1gnry06</bpmn:outgoing>
      <bpmn:errorEventDefinition camunda:errorCodeVariable="workflowProcessErrorCode" camunda:errorMessageVariable="workflowProcessErrorMessage" />
    </bpmn:boundaryEvent>
    <bpmn:sequenceFlow id="SequenceFlow_1gnry06" sourceRef="BoundaryEvent_0zugk5b" targetRef="ERROR_HANDLER" />
    <bpmn:scriptTask id="ERROR_HANDLER" name="Error Handler" scriptFormat="groovy">
      <bpmn:incoming>SequenceFlow_1gnry06</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1ckp4p8</bpmn:outgoing>
      <bpmn:script><![CDATA[     println "In Error Handler script";
     println "variables : " + execution.getVariables();]]></bpmn:script>
    </bpmn:scriptTask>
    <bpmn:sequenceFlow id="SequenceFlow_1ckp4p8" sourceRef="ERROR_HANDLER" targetRef="END_EVENT" />
  </bpmn:process>
  <bpmn:error id="Error_012mk4x" name="Error_2gml4ut" errorCode="EMAIL_FAILED" />
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="PM_DUMMY_WORKFLOW">
      <bpmndi:BPMNShape id="StartEvent_0wgt9l1_di" bpmnElement="START_EVENT">
        <dc:Bounds x="-428" y="220" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="-421" y="259" width="24" height="13" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_0lld5pj_di" bpmnElement="SequenceFlow_0lld5pj">
        <di:waypoint xsi:type="dc:Point" x="-392" y="238" />
        <di:waypoint xsi:type="dc:Point" x="-341" y="238" />
        <di:waypoint xsi:type="dc:Point" x="-341" y="238" />
        <di:waypoint xsi:type="dc:Point" x="-307" y="238" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="-371" y="231.5" width="90" height="13" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="ScriptTask_149bwyt_di" bpmnElement="Wait_Task">
        <dc:Bounds x="-307" y="198" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="EndEvent_1c3h4rs_di" bpmnElement="END_EVENT">
        <dc:Bounds x="40" y="220" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="49" y="259" width="20" height="13" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_1eckowf_di" bpmnElement="SequenceFlow_1eckowf">
        <di:waypoint xsi:type="dc:Point" x="-207" y="238" />
        <di:waypoint xsi:type="dc:Point" x="40" y="238" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="-128.5" y="216.5" width="90" height="13" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="BoundaryEvent_1ghibhe_di" bpmnElement="BoundaryEvent_0zugk5b">
        <dc:Bounds x="-282" y="260" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="-264.63451086956525" y="299" width="0" height="13" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_1gnry06_di" bpmnElement="SequenceFlow_1gnry06">
        <di:waypoint xsi:type="dc:Point" x="-264" y="296" />
        <di:waypoint xsi:type="dc:Point" x="-264" y="359" />
        <di:waypoint xsi:type="dc:Point" x="-235" y="359" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="-249" y="320.5" width="0" height="13" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="ScriptTask_10elca8_di" bpmnElement="ERROR_HANDLER">
        <dc:Bounds x="-235" y="320" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_1ckp4p8_di" bpmnElement="SequenceFlow_1ckp4p8">
        <di:waypoint xsi:type="dc:Point" x="-135" y="360" />
        <di:waypoint xsi:type="dc:Point" x="-47" y="360" />
        <di:waypoint xsi:type="dc:Point" x="-47" y="238" />
        <di:waypoint xsi:type="dc:Point" x="40" y="238" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="-32" y="292" width="0" height="13" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

#2

Hi @pankaj,

This is an open issue, see https://app.camunda.com/jira/browse/CAM-3864.

The workaround you describe sounds the best there is to me.

Cheers,
Thorben