{"record":{"id":"c966f3010430d39f","repo":"d2lang/d2","slug":"edge-not-found","errorCode":null,"errorMessage":"edge not found","messagePattern":"edge not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2oracle/edit.go","lineNumber":161,"sourceCode":"\tif len(boardPath) > 0 {\n\t\t// When compiling a nested board, we can read from boardG but only write to baseBoardG\n\t\tboardG = GetBoardGraph(g, boardPath)\n\t\tif boardG == nil {\n\t\t\treturn nil, fmt.Errorf(\"board %v not found\", boardPath)\n\t\t}\n\t\t// TODO beter name\n\t\tbaseAST = boardG.BaseAST\n\t\tif baseAST == nil {\n\t\t\treturn nil, fmt.Errorf(\"board %v cannot be modified through this file\", boardPath)\n\t\t}\n\t}\n\n\tobj := boardG.Root\n\tif mk.Key != nil {\n\t\tvar ok bool\n\t\tobj, ok = boardG.Root.HasChild(d2graph.Key(mk.Key))\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"edge not found\")\n\t\t}\n\t}\n\n\tedge, ok := obj.HasEdge(mk)\n\tif !ok {\n\t\treturn nil, errors.New(\"edge not found\")\n\t}\n\n\tif srcKey != nil {\n\t\tif edge.Src.AbsID() == *srcKey {\n\t\t\tsrcKey = nil\n\t\t}\n\t}\n\n\tif dstKey != nil {\n\t\tif edge.Dst.AbsID() == *dstKey {\n\t\t\tdstKey = nil\n\t\t}","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2oracle/edit.go#L143-L179","documentation":"ReconnectEdge is asked to reconnect the edge addressed by `key`, but the container object that the edge's key path resolves to does not exist in the board's graph. `boardG.Root.HasChild(d2graph.Key(mk.Key))` fails, meaning the prefix of the key before the edge has no matching object. The library refuses to proceed because there is no scope object to look the edge up under.","triggerScenarios":"Calling d2oracle.ReconnectEdge with a `key` like `x.(a -> b)` where the object path `x` (everything before the edge) does not exist in the graph, e.g. the node was deleted, renamed, or the key is typos/missing quotes for special characters.","commonSituations":"Editors replaying a stored key after a user renamed a container; keys built for the wrong board (nested boardPath given but edge lives on root); stale client state after a delete; keys whose IDs contain dots/spaces needing quoting (`\"a.b\"`) but passed raw.","solutions":["Verify the object prefix of the key exists in the graph before calling ReconnectEdge (compile the sketch and check HasChild / AbsID).","Fix typos or quote identifiers containing special characters: use `x.\"a.b\".(c -> d)` style quoting in the key string.","Confirm you are targeting the right board via boardPath; the edge's container must exist in that nested board.","Re-fetch the current key from the compiled graph instead of caching keys across edits."],"exampleFix":"// before\ng, err := d2oracle.ReconnectEdge(g, []string{\"root\"}, \"contianer.(a -> b)\", &newSrc, nil)\n// after (typo fixed and existence pre-checked)\nkey := \"container.(a -> b)\"\nif obj, ok := g.Root.HasChild([]string{\"container\"}); ok && obj.HasEdge(mk) {\n    g, err = d2oracle.ReconnectEdge(g, []string{\"root\"}, key, &newSrc, nil)\n}","handlingStrategy":"validation","validationCode":"mk, err := d2parser.ParseMapKey(key)\nif err != nil { return err }\nif mk.Key != nil {\n    if _, ok := g.Root.HasChild(d2graph.Key(mk.Key)); !ok {\n        return fmt.Errorf(\"container %v does not exist\", key)\n    }\n}","typeGuard":"func edgeContainerExists(g *d2graph.Graph, key string) bool {\n    mk, err := d2parser.ParseMapKey(key)\n    if err != nil || mk.Key == nil { return false }\n    _, ok := g.Root.HasChild(d2graph.Key(mk.Key))\n    return ok\n}","tryCatchPattern":"g2, err := d2oracle.ReconnectEdge(g, boardPath, key, &src, &dst)\nif err != nil {\n    if err.Error() == \"edge not found\" {\n        // re-derive key from current graph and retry once\n    }\n    return err\n}","preventionTips":["Always build keys from live graph data (AbsID/edge references), never from cached strings","Quote identifiers containing dots, spaces, or dashes","Confirm boardPath matches the board where the edge's container exists","Re-compile and re-fetch keys after any prior mutation"],"tags":["graph","edge","lookup","d2"],"backgroundTag":"edge-not-found","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}