mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 18:52:19 +00:00
fix: handle failed global subgraph blueprint loading gracefully (#9063)
## Summary Fix "Failed to load subgraph blueprints Error: [ASSERT] Workflow content should be loaded" error occurring on cloud. ## Changes - **What**: `getGlobalSubgraphData` now throws on API failure instead of returning empty string, global blueprint data is validated before loading, and individual global blueprint errors are properly propagated to the toast/console reporting instead of being silently swallowed. ## Review Focus Two root causes were fixed: 1. `getGlobalSubgraphData` returned `""` on failure — this empty string was set as `originalContent`, which is falsy, triggering the assertion in `ComfyWorkflow.load()`. 2. `loadInstalledBlueprints` used an internal `Promise.allSettled` whose results were discarded, so individual global blueprint failures never reached the error reporting in `fetchSubgraphs`. Fixes COM-15199 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9063-fix-handle-failed-global-subgraph-blueprint-loading-gracefully-30e6d73d3650818d9cc8ecf81cd0264e) by [Unito](https://www.unito.io)
This commit is contained in:
@@ -106,8 +106,13 @@ export class ComfyWorkflow extends UserFile {
|
|||||||
await super.load({ force })
|
await super.load({ force })
|
||||||
if (!force && this.isLoaded) return this as this & LoadedComfyWorkflow
|
if (!force && this.isLoaded) return this as this & LoadedComfyWorkflow
|
||||||
|
|
||||||
if (!this.originalContent) {
|
if (this.originalContent == null) {
|
||||||
throw new Error('[ASSERT] Workflow content should be loaded')
|
throw new Error(
|
||||||
|
`[ASSERT] Workflow content should be loaded for '${this.path}'`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (this.originalContent.trim().length === 0) {
|
||||||
|
throw new Error(`Workflow content is empty for '${this.path}'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState = JSON.parse(this.originalContent)
|
const initialState = JSON.parse(this.originalContent)
|
||||||
|
|||||||
@@ -1181,9 +1181,16 @@ export class ComfyApi extends EventTarget {
|
|||||||
|
|
||||||
async getGlobalSubgraphData(id: string): Promise<string> {
|
async getGlobalSubgraphData(id: string): Promise<string> {
|
||||||
const resp = await api.fetchApi('/global_subgraphs/' + id)
|
const resp = await api.fetchApi('/global_subgraphs/' + id)
|
||||||
if (resp.status !== 200) return ''
|
if (resp.status !== 200) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to fetch global subgraph '${id}': ${resp.status} ${resp.statusText}`
|
||||||
|
)
|
||||||
|
}
|
||||||
const subgraph: GlobalSubgraphData = await resp.json()
|
const subgraph: GlobalSubgraphData = await resp.json()
|
||||||
return subgraph?.data ?? ''
|
if (!subgraph?.data) {
|
||||||
|
throw new Error(`Global subgraph '${id}' returned empty data`)
|
||||||
|
}
|
||||||
|
return subgraph.data as string
|
||||||
}
|
}
|
||||||
async getGlobalSubgraphs(): Promise<Record<string, GlobalSubgraphData>> {
|
async getGlobalSubgraphs(): Promise<Record<string, GlobalSubgraphData>> {
|
||||||
const resp = await api.fetchApi('/global_subgraphs')
|
const resp = await api.fetchApi('/global_subgraphs')
|
||||||
|
|||||||
@@ -225,6 +225,68 @@ describe('useSubgraphStore', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should handle global blueprint with empty data gracefully', async () => {
|
||||||
|
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||||
|
await mockFetch(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
broken_blueprint: {
|
||||||
|
name: 'Broken Blueprint',
|
||||||
|
info: { node_pack: 'test_pack' },
|
||||||
|
data: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(consoleSpy).toHaveBeenCalledWith(
|
||||||
|
'Failed to load subgraph blueprint',
|
||||||
|
expect.any(Error)
|
||||||
|
)
|
||||||
|
expect(store.subgraphBlueprints).toHaveLength(0)
|
||||||
|
consoleSpy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handle global blueprint with rejected data promise gracefully', async () => {
|
||||||
|
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||||
|
await mockFetch(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
failing_blueprint: {
|
||||||
|
name: 'Failing Blueprint',
|
||||||
|
info: { node_pack: 'test_pack' },
|
||||||
|
data: Promise.reject(new Error('Network error')) as unknown as string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(consoleSpy).toHaveBeenCalledWith(
|
||||||
|
'Failed to load subgraph blueprint',
|
||||||
|
expect.any(Error)
|
||||||
|
)
|
||||||
|
expect(store.subgraphBlueprints).toHaveLength(0)
|
||||||
|
consoleSpy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should load valid global blueprints even when others fail', async () => {
|
||||||
|
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||||
|
await mockFetch(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
broken: {
|
||||||
|
name: 'Broken',
|
||||||
|
info: { node_pack: 'test_pack' },
|
||||||
|
data: ''
|
||||||
|
},
|
||||||
|
valid: {
|
||||||
|
name: 'Valid Blueprint',
|
||||||
|
info: { node_pack: 'test_pack' },
|
||||||
|
data: JSON.stringify(mockGraph)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(consoleSpy).toHaveBeenCalled()
|
||||||
|
expect(store.subgraphBlueprints).toHaveLength(1)
|
||||||
|
consoleSpy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
describe('search_aliases support', () => {
|
describe('search_aliases support', () => {
|
||||||
it('should include search_aliases from workflow extra', async () => {
|
it('should include search_aliases from workflow extra', async () => {
|
||||||
const mockGraphWithAliases = {
|
const mockGraphWithAliases = {
|
||||||
|
|||||||
@@ -198,13 +198,19 @@ export const useSubgraphStore = defineStore('subgraph', () => {
|
|||||||
}
|
}
|
||||||
async function loadInstalledBlueprints() {
|
async function loadInstalledBlueprints() {
|
||||||
async function loadGlobalBlueprint([k, v]: [string, GlobalSubgraphData]) {
|
async function loadGlobalBlueprint([k, v]: [string, GlobalSubgraphData]) {
|
||||||
|
const data = await v.data
|
||||||
|
if (typeof data !== 'string' || data.trim().length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
`Global blueprint '${v.name}' (${k}) returned empty content`
|
||||||
|
)
|
||||||
|
}
|
||||||
const path = SubgraphBlueprint.basePath + v.name + '.json'
|
const path = SubgraphBlueprint.basePath + v.name + '.json'
|
||||||
const blueprint = new SubgraphBlueprint({
|
const blueprint = new SubgraphBlueprint({
|
||||||
path,
|
path,
|
||||||
modified: Date.now(),
|
modified: Date.now(),
|
||||||
size: -1
|
size: -1
|
||||||
})
|
})
|
||||||
blueprint.originalContent = blueprint.content = await v.data
|
blueprint.originalContent = blueprint.content = data
|
||||||
blueprint.filename = v.name
|
blueprint.filename = v.name
|
||||||
useWorkflowStore().attachWorkflow(blueprint)
|
useWorkflowStore().attachWorkflow(blueprint)
|
||||||
const loaded = await blueprint.load()
|
const loaded = await blueprint.load()
|
||||||
@@ -238,16 +244,19 @@ export const useSubgraphStore = defineStore('subgraph', () => {
|
|||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
await Promise.allSettled(filteredEntries.map(loadGlobalBlueprint))
|
return Promise.allSettled(filteredEntries.map(loadGlobalBlueprint))
|
||||||
}
|
}
|
||||||
|
|
||||||
const userSubs = (
|
const userSubs = (
|
||||||
await api.listUserDataFullInfo(SubgraphBlueprint.basePath)
|
await api.listUserDataFullInfo(SubgraphBlueprint.basePath)
|
||||||
).filter((f) => f.path.endsWith('.json'))
|
).filter((f) => f.path.endsWith('.json'))
|
||||||
const settled = await Promise.allSettled([
|
const [globalResult, ...userResults] = await Promise.allSettled([
|
||||||
...userSubs.map(loadBlueprint),
|
loadInstalledBlueprints(),
|
||||||
loadInstalledBlueprints()
|
...userSubs.map(loadBlueprint)
|
||||||
])
|
])
|
||||||
|
const globalResults =
|
||||||
|
globalResult.status === 'fulfilled' ? globalResult.value : []
|
||||||
|
const settled = [...globalResults, ...userResults]
|
||||||
|
|
||||||
const errors = settled.filter((i) => 'reason' in i).map((i) => i.reason)
|
const errors = settled.filter((i) => 'reason' in i).map((i) => i.reason)
|
||||||
errors.forEach((e) => console.error('Failed to load subgraph blueprint', e))
|
errors.forEach((e) => console.error('Failed to load subgraph blueprint', e))
|
||||||
|
|||||||
Reference in New Issue
Block a user