Skip to content

Commit 164800f

Browse files
authored
fix(core): Replace misleading "No path back to node" error with helpful execution message (#17759)
1 parent d16960b commit 164800f

File tree

4 files changed

+709
-8
lines changed

4 files changed

+709
-8
lines changed

packages/workflow/src/workflow-data-proxy.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,13 @@ export class WorkflowDataProxy {
10801080
!that?.runExecutionData?.resultData?.runData.hasOwnProperty(nodeName) &&
10811081
!getPinDataIfManualExecution(that.workflow, nodeName, that.mode)
10821082
) {
1083-
throw createNodeReferenceError(nodeName);
1083+
// Always show helpful "Execute node for preview" message
1084+
throw new ExpressionError(EXPRESSION_ERROR_MESSAGES.NO_EXECUTION_DATA, {
1085+
messageTemplate: `Execute node "${nodeName}" for preview`,
1086+
nodeCause: nodeName,
1087+
runIndex: that.runIndex,
1088+
itemIndex: that.itemIndex,
1089+
});
10841090
}
10851091
};
10861092

@@ -1098,7 +1104,10 @@ export class WorkflowDataProxy {
10981104
contextNode = parentMainInputNode?.name ?? contextNode;
10991105
}
11001106

1101-
if (!that.workflow.hasPath(nodeName, contextNode)) {
1107+
// For .first(), .last(), .all() methods, use unidirectional path checking
1108+
// (forward only) to maintain traditional paired item behavior
1109+
const hasForwardPath = that.workflow.getChildNodes(nodeName).includes(contextNode);
1110+
if (!hasForwardPath) {
11021111
throw createNodeReferenceError(nodeName);
11031112
}
11041113
};

packages/workflow/src/workflow.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,24 @@ export class Workflow {
676676
return returnConns;
677677
}
678678

679-
getParentMainInputNode(node: INode | null | undefined): INode | null | undefined {
679+
getParentMainInputNode(
680+
node: INode | null | undefined,
681+
visitedNodes: Set<string> = new Set(),
682+
): INode | null | undefined {
680683
if (!node) return node;
681684

685+
// Prevent infinite recursion by tracking visited nodes
686+
if (visitedNodes.has(node.name)) {
687+
return node;
688+
}
689+
visitedNodes.add(node.name);
690+
682691
const nodeConnections = this.connectionsBySourceNode[node.name];
683-
if (!nodeConnections) return node;
692+
if (!nodeConnections) {
693+
return node;
694+
}
684695

685-
// Get non-main connection types
696+
// Get non-main connection types that this node connects TO (outgoing connections)
686697
const nonMainConnectionTypes = Object.keys(nodeConnections).filter(
687698
(type) => type !== NodeConnectionTypes.Main,
688699
);
@@ -696,7 +707,7 @@ export class Workflow {
696707
if (!returnNode) {
697708
throw new ApplicationError(`Node "${connection.node}" not found`);
698709
}
699-
return this.getParentMainInputNode(returnNode);
710+
return this.getParentMainInputNode(returnNode, visitedNodes);
700711
}
701712
}
702713
}

0 commit comments

Comments
 (0)