workflowErrors.js
JavaScript · 18 рядків
1export function locateWorkflowErrors(workflow, errors = []) {
2 const nodeErrors = {}
3 const edgeErrors = {}
4 const nodes = [...(workflow?.nodes || [])].sort((a, b) => b.name.length - a.name.length)
5
6 for (const error of errors) {
7 const text = String(error?.message || error)
8 const explicitEdge = error?.edgeId && workflow?.edges?.find(item => item.id === error.edgeId)
9 const explicitNode = error?.nodeId && workflow?.nodes?.find(item => item.id === error.nodeId)
10 const edge = workflow?.edges?.find(item => text.includes(item.id))
11 const cycleId = text.match(/Cycle detected at node (.+)$/)?.[1]
12 const node = nodes.find(item => item.id === cycleId || text.startsWith(`${item.name}:`) || text.startsWith(`${item.name} ·`))
13 if (explicitEdge || edge) (edgeErrors[(explicitEdge || edge).id] ||= []).push(text)
14 if (explicitNode || node) (nodeErrors[(explicitNode || node).id] ||= []).push(text)
15 }
16 return { nodeErrors, edgeErrors }
17}
18