Skip to content

Commit 973a1eb

Browse files
authored
[Bug] Guard link fixer with try-catch (#3806)
1 parent b9d9ce7 commit 973a1eb

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

src/composables/useWorkflowValidation.ts

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,55 @@ import { fixBadLinks } from '@/utils/linkFixer'
77

88
export interface ValidationResult {
99
graphData: ComfyWorkflowJSON | null
10-
linksFixes?: {
11-
patched: number
12-
deleted: number
13-
}
1410
}
1511

1612
export function useWorkflowValidation() {
1713
const toastStore = useToastStore()
1814

15+
function tryFixLinks(
16+
graphData: ComfyWorkflowJSON,
17+
options: { silent?: boolean } = {}
18+
) {
19+
const { silent = false } = options
20+
21+
// Collect all logs in an array
22+
const logs: string[] = []
23+
// Then validate and fix links if schema validation passed
24+
const linkValidation = fixBadLinks(
25+
graphData as unknown as ISerialisedGraph,
26+
{
27+
fix: true,
28+
silent,
29+
logger: {
30+
log: (message: string) => {
31+
logs.push(message)
32+
}
33+
}
34+
}
35+
)
36+
37+
if (!silent && logs.length > 0) {
38+
toastStore.add({
39+
severity: 'warn',
40+
summary: 'Workflow Validation',
41+
detail: logs.join('\n')
42+
})
43+
}
44+
45+
// If links were fixed, notify the user
46+
if (linkValidation.fixed) {
47+
if (!silent) {
48+
toastStore.add({
49+
severity: 'success',
50+
summary: 'Workflow Links Fixed',
51+
detail: `Fixed ${linkValidation.patched} node connections and removed ${linkValidation.deleted} invalid links.`
52+
})
53+
}
54+
}
55+
56+
return linkValidation.graph as unknown as ComfyWorkflowJSON
57+
}
58+
1959
/**
2060
* Validates a workflow, including link validation and schema validation
2161
*/
@@ -27,7 +67,6 @@ export function useWorkflowValidation() {
2767
): Promise<ValidationResult> {
2868
const { silent = false } = options
2969

30-
let linksFixes
3170
let validatedData: ComfyWorkflowJSON | null = null
3271

3372
// First do schema validation
@@ -41,51 +80,16 @@ export function useWorkflowValidation() {
4180
)
4281

4382
if (validatedGraphData) {
44-
// Collect all logs in an array
45-
const logs: string[] = []
46-
// Then validate and fix links if schema validation passed
47-
const linkValidation = fixBadLinks(
48-
validatedGraphData as unknown as ISerialisedGraph,
49-
{
50-
fix: true,
51-
silent,
52-
logger: {
53-
log: (message: string) => {
54-
logs.push(message)
55-
}
56-
}
57-
}
58-
)
59-
60-
if (!silent && logs.length > 0) {
61-
toastStore.add({
62-
severity: 'warn',
63-
summary: 'Workflow Validation',
64-
detail: logs.join('\n')
65-
})
66-
}
67-
68-
// If links were fixed, notify the user
69-
if (linkValidation.fixed) {
70-
if (!silent) {
71-
toastStore.add({
72-
severity: 'success',
73-
summary: 'Workflow Links Fixed',
74-
detail: `Fixed ${linkValidation.patched} node connections and removed ${linkValidation.deleted} invalid links.`
75-
})
76-
}
77-
}
78-
79-
validatedData = linkValidation.graph as unknown as ComfyWorkflowJSON
80-
linksFixes = {
81-
patched: linkValidation.patched,
82-
deleted: linkValidation.deleted
83+
try {
84+
validatedData = tryFixLinks(validatedGraphData, { silent })
85+
} catch (err) {
86+
// Link fixer itself is throwing an error
87+
console.error(err)
8388
}
8489
}
8590

8691
return {
87-
graphData: validatedData,
88-
linksFixes
92+
graphData: validatedData
8993
}
9094
}
9195

0 commit comments

Comments
 (0)