Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mdl/executor/cmd_microflows_builder_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (fb *flowBuilder) addEnumSplit(s *ast.EnumSplitStmt) model.ID {
lastID := model.ID("")
pendingCase := ""
var prevAnchor *ast.FlowAnchors
for _, stmt := range br.body {
for j, stmt := range br.body {
thisAnchor := stmtOwnAnchor(stmt)
actID := fb.addStatement(stmt)
if actID == "" {
Expand Down Expand Up @@ -376,6 +376,9 @@ func (fb *flowBuilder) addEnumSplit(s *ast.EnumSplitStmt) model.ID {
}
applyUserAnchors(flow, prevAnchor, thisAnchor)
fb.flows = append(fb.flows, flow)
if fb.emptyErrorHandlerFrom == lastID {
fb.addPendingErrorHandlerFlowForStatement(lastID, actID, stmt, statementsReferenceVar(br.body[j+1:], fb.errorHandlerSkipVar))
}
}
prevAnchor = thisAnchor
if fb.nextConnectionPoint != "" {
Expand Down
10 changes: 8 additions & 2 deletions mdl/executor/cmd_microflows_builder_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
var prevThenAnchor *ast.FlowAnchors
var pendingThenCase string
var pendingThenAnchor *ast.FlowAnchors
for _, stmt := range s.ThenBody {
for i, stmt := range s.ThenBody {
thisAnchor := stmtOwnAnchor(stmt)
actID := fb.addStatement(stmt)
if actID != "" {
Expand Down Expand Up @@ -152,6 +152,9 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
}
applyUserAnchors(flow, originAnchor, destAnchor)
fb.flows = append(fb.flows, flow)
if fb.emptyErrorHandlerFrom == lastThenID {
fb.addPendingErrorHandlerFlowForStatement(lastThenID, actID, stmt, statementsReferenceVar(s.ThenBody[i+1:], fb.errorHandlerSkipVar))
}
}
prevThenAnchor = thisAnchor
// For nested compound statements, use their exit point
Expand Down Expand Up @@ -209,7 +212,7 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
var prevElseAnchor *ast.FlowAnchors
var pendingElseCase string
var pendingElseAnchor *ast.FlowAnchors
for _, stmt := range s.ElseBody {
for i, stmt := range s.ElseBody {
thisAnchor := stmtOwnAnchor(stmt)
actID := fb.addStatement(stmt)
if actID != "" {
Expand Down Expand Up @@ -237,6 +240,9 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
}
applyUserAnchors(flow, originAnchor, destAnchor)
fb.flows = append(fb.flows, flow)
if fb.emptyErrorHandlerFrom == lastElseID {
fb.addPendingErrorHandlerFlowForStatement(lastElseID, actID, stmt, statementsReferenceVar(s.ElseBody[i+1:], fb.errorHandlerSkipVar))
}
}
prevElseAnchor = thisAnchor
// For nested compound statements, use their exit point
Expand Down
52 changes: 52 additions & 0 deletions mdl/executor/cmd_microflows_builder_terminal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,58 @@ func TestBuildFlowGraph_EmptyNoOutputHandlerRejoinsAtNextAction(t *testing.T) {
t.Fatal("empty no-output handler should rejoin at the next action")
}

func TestBuildFlowGraph_EmptyNoOutputHandlerInIfBranchRejoinsAtNextAction(t *testing.T) {
body := []ast.MicroflowStatement{
&ast.IfStmt{
Condition: &ast.VariableExpr{Name: "ShouldRefresh"},
HasElse: true,
ThenBody: []ast.MicroflowStatement{
&ast.CallMicroflowStmt{
MicroflowName: ast.QualifiedName{Module: "Synthetic", Name: "RefreshCache"},
ErrorHandling: &ast.ErrorHandlingClause{Type: ast.ErrorHandlingCustomWithoutRollback},
},
&ast.CallJavaActionStmt{
OutputVariable: "ProcessedCount",
ActionName: ast.QualifiedName{Module: "Synthetic", Name: "CountProcessedItems"},
},
},
ElseBody: []ast.MicroflowStatement{
&ast.ReturnStmt{},
},
},
}

fb := &flowBuilder{posX: 100, posY: 100, spacing: HorizontalSpacing, measurer: &layoutMeasurer{}}
oc := fb.buildFlowGraph(body, nil)

var callID, javaID model.ID
for _, obj := range oc.Objects {
activity, ok := obj.(*microflows.ActionActivity)
if !ok {
continue
}
switch action := activity.Action.(type) {
case *microflows.MicroflowCallAction:
if action.MicroflowCall != nil && action.MicroflowCall.Microflow == "Synthetic.RefreshCache" {
callID = activity.ID
}
case *microflows.JavaActionCallAction:
if action.ResultVariableName == "ProcessedCount" {
javaID = activity.ID
}
}
}
if callID == "" || javaID == "" {
t.Fatalf("expected no-output call and branch continuation; got call=%q java=%q", callID, javaID)
}
for _, flow := range oc.Flows {
if flow.IsErrorHandler && flow.OriginID == callID && flowPathExists(oc.Flows, flow.DestinationID, javaID) {
return
}
}
t.Fatal("empty no-output handler inside IF branch should rejoin at the next branch action")
}

func TestBuildFlowGraph_ErrorHandlerEmptyElseKeepsFalseCaseOnRejoin(t *testing.T) {
body := []ast.MicroflowStatement{
&ast.CallMicroflowStmt{
Expand Down
Loading