[Bug] compose: Workflow.Compile panics when a branch end node has not been added
Describe the bug
Workflow.Compile panics with a nil pointer dereference when a branch names an end node that was never added. compile in compose/workflow.go does:
n := wf.workflowNodes[endNode]
n.dependencySetter(wb.fromNodeKey, branchDependency)workflowNodes is a map. A missing key yields a nil *WorkflowNode, and calling dependencySetter panics. Compile does not recover, so the panic reaches the caller.
The same missing end node on a Graph returns branch end node '...' needs to be added to graph first, because addBranch(..., skipData=false) checks that the node exists. Workflow.compile calls addBranch with skipData=true, which skips that check, and the panic happens before addBranch is called.
To Reproduce
wf := compose.NewWorkflow[string, string]()
wf.AddLambdaNode("1", compose.InvokableLambda(func(ctx context.Context, in string) (string, error) {
return in, nil
})).AddInput(compose.START)
wf.AddBranch("1", compose.NewGraphBranch(func(ctx context.Context, in string) (string, error) {
return "2", nil
}, map[string]bool{"2": true})) // node "2" is never added
wf.End().AddInput("1")
_, err := wf.Compile(ctx)On alpha/10 @ 6fc7859 this fails with:
panic: runtime error: invalid memory address or nil pointer dereference
compose/workflow.go:454
compose/workflow.go:83Expected behavior
Compile returns an error, for example branch end node '2' needs to be added to workflow first.
Version:
alpha/10 @ 6fc7859 (compose/workflow.go:454).
Source: cloudwego/eino