{"record":{"id":"106531e84b5a0300","repo":"d2lang/d2","slug":"newsrc-not-found","errorCode":null,"errorMessage":"newSrc not found","messagePattern":"newSrc not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2oracle/edit.go","lineNumber":195,"sourceCode":"\t\tif edge.Dst.AbsID() == *dstKey {\n\t\t\tdstKey = nil\n\t\t}\n\t}\n\n\tif srcKey == nil && dstKey == nil {\n\t\treturn g, nil\n\t}\n\n\tvar src *d2graph.Object\n\tvar dst *d2graph.Object\n\tif srcKey != nil {\n\t\tsrcmk, err := d2parser.ParseMapKey(*srcKey)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tsrc, ok = boardG.Root.HasChild(d2graph.Key(srcmk.Key))\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"newSrc not found\")\n\t\t}\n\t}\n\tif dstKey != nil {\n\t\tdstmk, err := d2parser.ParseMapKey(*dstKey)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tdst, ok = boardG.Root.HasChild(d2graph.Key(dstmk.Key))\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"newDst not found\")\n\t\t}\n\t}\n\n\trefs := edge.References\n\tif baseAST != g.AST {\n\t\trefs = GetWriteableEdgeRefs(edge, baseAST)\n\t\tif len(refs) == 0 || refs[0].ScopeAST != baseAST {\n\t\t\t// TODO null","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2oracle/edit.go#L177-L213","documentation":"ReconnectEdge resolved the new source endpoint via `boardG.Root.HasChild`, but no object exists for the `srcKey` you passed. The edge's existing endpoints are found; the replacement source is not. Unlike the edge's other endpoints, ReconnectEdge does not create missing nodes for the new endpoint lookup.","triggerScenarios":"Calling d2oracle.ReconnectEdge with `srcKey` pointing to a node that does not exist in the target board: typo, node deleted earlier, node lives in a different board than boardPath, or an absolute ID that doesn't match the graph (e.g. wrong quotes/escapes).","commonSituations":"Batch scripts reconnecting edges after bulk node deletion; renaming a node then reconnecting with the old name; passing IDs from a different nested board; special characters in IDs not quoted.","solutions":["Create the new source node first (e.g. via d2oracle.Create) so it exists in the graph before reconnecting.","Verify srcKey resolves: parse it and check g.Root.HasChild(d2graph.Key(...)) before calling.","Use the node's AbsID() as srcKey to guarantee exact matching.","Ensure srcKey refers to a node in the same board passed via boardPath."],"exampleFix":"// before\ng, err = d2oracle.ReconnectEdge(g, nil, \"x.(a -> b)\", &newSrc, nil) // newSrc=\"q\" doesn't exist\n// after: ensure node exists first\nif _, ok := g.Root.HasChild([]string{\"q\"}); !ok {\n    g, _, err = d2oracle.Create(g, nil, \"q\", nil)\n}\ng, err = d2oracle.ReconnectEdge(g, nil, \"x.(a -> b)\", &newSrc, nil)","handlingStrategy":"validation","validationCode":"srcmk, err := d2parser.ParseMapKey(newSrc)\nif err != nil { return err }\nif _, ok := g.Root.HasChild(d2graph.Key(srcmk.Key)); !ok {\n    g, _, err = d2oracle.Create(g, nil, newSrc, nil)\n    if err != nil { return err }\n}","typeGuard":"func nodeExists(g *d2graph.Graph, id string) bool {\n    mk, err := d2parser.ParseMapKey(id)\n    if err != nil { return false }\n    _, ok := g.Root.HasChild(d2graph.Key(mk.Key))\n    return ok\n}","tryCatchPattern":"g2, err := d2oracle.ReconnectEdge(g, nil, key, &newSrc, &newDst)\nif err != nil && err.Error() == \"newSrc not found\" {\n    g, _, err = d2oracle.Create(g, nil, newSrc, nil)\n    if err != nil { return err }\n    g2, err = d2oracle.ReconnectEdge(g, nil, key, &newSrc, &newDst)\n}","preventionTips":["Create endpoint nodes before reconnecting edges to them","Pass node AbsID() values as srcKey/dstKey","Keep node existence checks next to every rewire operation","Watch for nodes created inside nested boards that are invisible to the target board"],"tags":["graph","edge","node-lookup","d2"],"backgroundTag":"node-not-found","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}