Skip to content

Commit 849bdc1

Browse files
authored
Update workflow object handling and validation
Refactor workflow object handling to allow undefined type and improve validation checks.
1 parent d14ddcb commit 849bdc1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/scripts/app.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,26 +1441,29 @@ 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
1444+
let workflowObj: ComfyWorkflowJSON | undefined
14451445
try {
14461446
workflowObj =
14471447
typeof workflow === 'string' ? JSON.parse(workflow) : workflow
14481448
} catch (err) {
14491449
console.error('Failed to parse workflow:', err)
14501450
this.showErrorOnFileLoad(file)
1451+
// Fall through to check parameters as fallback
14511452
}
14521453

1453-
// Validate workflow is a proper object
1454+
// Only load workflow if parsing succeeded AND validation passed
14541455
if (
1455-
typeof workflowObj !== 'object' ||
1456-
Array.isArray(workflowObj)
1456+
workflowObj &&
1457+
typeof workflowObj === 'object' &&
1458+
!Array.isArray(workflowObj)
14571459
) {
1458-
console.error('Invalid workflow structure')
1459-
} else {
14601460
await this.loadGraphData(workflowObj, true, true, fileName, {
14611461
openSource
14621462
})
14631463
return
1464+
} else if (workflowObj !== undefined) {
1465+
console.error('Invalid workflow structure, trying parameters fallback')
1466+
this.showErrorOnFileLoad(file)
14641467
}
14651468
}
14661469

0 commit comments

Comments
 (0)