Skip to content

Commit 2930334

Browse files
committed
fix: avoid custom-handler var-ref helper collision
Symptom: merging the custom error-handler routing PR with the variable-alias PR would redeclare statementVarRefs and statementsVarRefs in package executor. Root cause: both PRs added local helper names for different pre-passes while sharing the same package namespace. Fix: rename the custom error-handler helper pair to handler-specific names and add review-requested comments documenting the pending-handler state invariant, the bounded rejoin scan, and the top-entry anchor used for error-handler flows. Tests: make build; focused error-handler executor tests; make test.
1 parent 839eb7d commit 2930334

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

mdl/executor/cmd_microflows_builder.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ type flowBuilder struct {
4848
// previousStmtAnchor holds the Anchor annotation of the statement that
4949
// just emitted an activity, so the next flow's OriginConnectionIndex can
5050
// be overridden by the user. Cleared after each flow is created.
51-
previousStmtAnchor *ast.FlowAnchors
51+
previousStmtAnchor *ast.FlowAnchors
52+
// Pending custom error-handler routing uses two representations: the
53+
// currently active handler lives in the flat fields below, while handlers
54+
// postponed across branch boundaries are queued in pendingErrorHandlers.
55+
// Mutate this state through the helper methods in builder_flows.go so the
56+
// active/queued invariant stays synchronized.
5257
emptyErrorHandlerFrom model.ID
5358
errorHandlerTailFrom model.ID
5459
errorHandlerSource model.ID

mdl/executor/cmd_microflows_builder_flows.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ func (fb *flowBuilder) addErrorHandlerRejoinFlowForState(state pendingErrorHandl
265265
}
266266

267267
func (fb *flowBuilder) findExistingRejoinMerge(originID, destinationID model.ID) model.ID {
268+
// Error-handler rejoins are rare and microflows are small enough that an
269+
// O(objects*flows) scan keeps the write path simpler than maintaining an
270+
// incremental merge index.
268271
for _, flow := range fb.flows {
269272
if flow.OriginID != originID || flow.IsErrorHandler {
270273
continue
@@ -296,7 +299,7 @@ func statementReferencesVar(stmt ast.MicroflowStatement, varName string) bool {
296299
if stmt == nil || varName == "" {
297300
return false
298301
}
299-
for _, ref := range statementVarRefs(stmt) {
302+
for _, ref := range errorHandlerStatementVarRefs(stmt) {
300303
if ref == varName {
301304
return true
302305
}
@@ -316,7 +319,7 @@ func statementsReferenceVar(stmts []ast.MicroflowStatement, varName string) bool
316319
return false
317320
}
318321

319-
func statementVarRefs(stmt ast.MicroflowStatement) []string {
322+
func errorHandlerStatementVarRefs(stmt ast.MicroflowStatement) []string {
320323
var refs []string
321324
switch s := stmt.(type) {
322325
case *ast.DeclareStmt:
@@ -331,14 +334,14 @@ func statementVarRefs(stmt ast.MicroflowStatement) []string {
331334
}
332335
case *ast.IfStmt:
333336
refs = append(refs, exprVarRefs(s.Condition)...)
334-
refs = append(refs, statementsVarRefs(s.ThenBody)...)
335-
refs = append(refs, statementsVarRefs(s.ElseBody)...)
337+
refs = append(refs, errorHandlerStatementsVarRefs(s.ThenBody)...)
338+
refs = append(refs, errorHandlerStatementsVarRefs(s.ElseBody)...)
336339
case *ast.WhileStmt:
337340
refs = append(refs, exprVarRefs(s.Condition)...)
338-
refs = append(refs, statementsVarRefs(s.Body)...)
341+
refs = append(refs, errorHandlerStatementsVarRefs(s.Body)...)
339342
case *ast.LoopStmt:
340343
refs = append(refs, s.ListVariable)
341-
refs = append(refs, statementsVarRefs(s.Body)...)
344+
refs = append(refs, errorHandlerStatementsVarRefs(s.Body)...)
342345
case *ast.MfSetStmt:
343346
refs = append(refs, extractVarName(s.Target))
344347
refs = append(refs, exprVarRefs(s.Value)...)
@@ -394,16 +397,18 @@ func statementVarRefs(stmt ast.MicroflowStatement) []string {
394397
return refs
395398
}
396399

397-
func statementsVarRefs(stmts []ast.MicroflowStatement) []string {
400+
func errorHandlerStatementsVarRefs(stmts []ast.MicroflowStatement) []string {
398401
var refs []string
399402
for _, stmt := range stmts {
400-
refs = append(refs, statementVarRefs(stmt)...)
403+
refs = append(refs, errorHandlerStatementVarRefs(stmt)...)
401404
}
402405
return refs
403406
}
404407

405408
// newErrorHandlerFlow creates a SequenceFlow with IsErrorHandler=true,
406-
// connecting from the bottom of the source activity to the left of the error handler.
409+
// connecting from the bottom of the source activity to the top of the handler.
410+
// Studio Pro lays custom error handlers below their source, so the destination
411+
// anchor enters from above rather than from the normal left-side continuation.
407412
func newErrorHandlerFlow(originID, destinationID model.ID) *microflows.SequenceFlow {
408413
return &microflows.SequenceFlow{
409414
BaseElement: model.BaseElement{ID: model.ID(types.GenerateID())},

0 commit comments

Comments
 (0)