Skip to content

Commit f3960f0

Browse files
committed
fix: make annotateDirtyNodesWithError return new nodes instead of mutating
node.data.error and node.data.extendedError were being set directly on node objects, bypassing the immutable update pattern used elsewhere in the codebase. Both call sites (payload-limit path and network-error path) now consume the returned mapped array.
1 parent 7543ec7 commit f3960f0

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

src/lib/graphUtils.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,10 @@ async function loadBackendLimits(baseUrl: string): Promise<BackendLimits> {
106106
function annotateDirtyNodesWithError(
107107
nodes: Node<CalculationNodeData>[],
108108
message: string
109-
) {
110-
nodes.forEach((node) => {
111-
if (node.data?.dirty) {
112-
node.data.error = true;
113-
node.data.extendedError = message;
114-
}
109+
): Node<CalculationNodeData>[] {
110+
return nodes.map((node) => {
111+
if (!node.data?.dirty) return node;
112+
return { ...node, data: { ...node.data, error: true, extendedError: message } };
115113
});
116114
}
117115

@@ -178,9 +176,8 @@ export async function recalculateGraph(
178176
const limitMessage = `Request is ${formatBytes(
179177
payloadBytes
180178
)}, over the server limit (${formatBytes(maxPayloadBytes)}).`;
181-
annotateDirtyNodesWithError(nodes, limitMessage);
182179
return {
183-
nodes,
180+
nodes: annotateDirtyNodesWithError(nodes, limitMessage),
184181
version,
185182
errors: [{ nodeId: PAYLOAD_LIMIT_NODE_ID, error: limitMessage }],
186183
};
@@ -223,11 +220,8 @@ export async function recalculateGraph(
223220
? "Backend not running. Start it with: python routes.py"
224221
: "Cannot connect to calculation service. Please try again later.";
225222

226-
// Mark all dirty nodes with error
227-
annotateDirtyNodesWithError(nodes, message);
228-
229223
return {
230-
nodes: nodes,
224+
nodes: annotateDirtyNodesWithError(nodes, message),
231225
version: version,
232226
errors: [], // No system error - the node errors are enough
233227
};

0 commit comments

Comments
 (0)