Skip to content

Commit 3689d05

Browse files
authored
Refactor workflow parsing and validation logic
1 parent 849bdc1 commit 3689d05

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/scripts/app.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,30 +1441,30 @@ export class ComfyApp {
14411441
// Check workflow first - it should take priority over parameters
14421442
// when both are present (e.g., in ComfyUI-generated PNGs)
14431443
if (workflow) {
1444-
let workflowObj: ComfyWorkflowJSON | undefined
1444+
let workflowObj: ComfyWorkflowJSON | undefined = undefined
14451445
try {
14461446
workflowObj =
14471447
typeof workflow === 'string' ? JSON.parse(workflow) : workflow
1448+
1449+
// Only load workflow if parsing succeeded AND validation passed
1450+
if (
1451+
workflowObj &&
1452+
typeof workflowObj === 'object' &&
1453+
!Array.isArray(workflowObj)
1454+
) {
1455+
await this.loadGraphData(workflowObj, true, true, fileName, {
1456+
openSource
1457+
})
1458+
return
1459+
} else {
1460+
console.error('Invalid workflow structure, trying parameters fallback')
1461+
this.showErrorOnFileLoad(file)
1462+
}
14481463
} catch (err) {
14491464
console.error('Failed to parse workflow:', err)
14501465
this.showErrorOnFileLoad(file)
14511466
// Fall through to check parameters as fallback
14521467
}
1453-
1454-
// Only load workflow if parsing succeeded AND validation passed
1455-
if (
1456-
workflowObj &&
1457-
typeof workflowObj === 'object' &&
1458-
!Array.isArray(workflowObj)
1459-
) {
1460-
await this.loadGraphData(workflowObj, true, true, fileName, {
1461-
openSource
1462-
})
1463-
return
1464-
} else if (workflowObj !== undefined) {
1465-
console.error('Invalid workflow structure, trying parameters fallback')
1466-
this.showErrorOnFileLoad(file)
1467-
}
14681468
}
14691469

14701470
// Use parameters as fallback when no workflow exists

0 commit comments

Comments
 (0)