fix: add debugging context to NullGraphError throws

- Add node ID to NullGraphError messages for easier debugging
- Add test verifying rootGraph throws after node removal

Amp-Thread-ID: https://ampcode.com/threads/T-019c0dad-0101-74ca-92fd-0fd1a992d889
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
bymyself
2026-01-30 00:12:20 -08:00
parent a2b3d93a00
commit e757836366
3 changed files with 18 additions and 2 deletions

View File

@@ -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(

View File

@@ -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 }) => {

View File

@@ -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
}