diff --git a/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts b/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts index a786da066..bb93d0e69 100644 --- a/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts +++ b/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts @@ -194,7 +194,10 @@ export class ExecutableNodeDTO implements ExecutableLGraphNode { } } - if (!subgraphNode.graph) throw new NullGraphError() + if (!subgraphNode.graph) + throw new NullGraphError( + `SubgraphNode ${subgraphNode.id} has no graph during input resolution` + ) const outerLink = subgraphNode.graph.getLink(linkId) if (!outerLink) throw new InvalidLinkError( diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.test.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.test.ts index 384e8c9d6..d37bf070f 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.test.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.test.ts @@ -59,6 +59,18 @@ describe.skip('SubgraphNode Construction', () => { expect(subgraphNode.rootGraph).toBe(parentGraph.rootGraph) }) + it('should throw NullGraphError when accessing rootGraph after removal', () => { + const subgraph = createTestSubgraph() + const subgraphNode = createTestSubgraphNode(subgraph) + const parentGraph = subgraphNode.graph! + parentGraph.add(subgraphNode) + + parentGraph.remove(subgraphNode) + + expect(() => subgraphNode.rootGraph).toThrow() + expect(subgraphNode.graph).toBeNull() + }) + subgraphTest( 'should synchronize slots with subgraph definition', ({ subgraphWithNode }) => { diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.ts index 235aedd60..cd8b0a7e4 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.ts @@ -51,7 +51,8 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph { override graph: GraphOrSubgraph | null get rootGraph(): LGraph { - if (!this.graph) throw new NullGraphError() + if (!this.graph) + throw new NullGraphError(`SubgraphNode ${this.id} has no graph`) return this.graph.rootGraph }