{"record":{"id":"3be12635879e6dd5","repo":"d2lang/d2","slug":"object-not-found","errorCode":null,"errorMessage":"object not found","messagePattern":"object not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2oracle/edit.go","lineNumber":1411,"sourceCode":"\t\t\t\tid == \"height\" ||\n\t\t\t\tid == \"left\" ||\n\t\t\t\tid == \"top\" ||\n\t\t\t\tid == \"link\" {\n\t\t\t\tdeleted, err := deleteObjField(g, baseAST, obj, id)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tif !deleted && imported {\n\t\t\t\t\tmk.Value = d2ast.MakeValueBox(&d2ast.Null{})\n\t\t\t\t\tappendMapKey(baseAST, mk)\n\t\t\t\t} else {\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t\tobj, ok = obj.HasChild([]string{id})\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"object not found\")\n\t\t}\n\t\timported = IsImportedObj(baseAST, obj)\n\t}\n\n\treturn recompile(g)\n}\n\nfunc deleteMapField(m *d2ast.Map, field string) (deleted bool) {\n\tfor i := 0; i < len(m.Nodes); i++ {\n\t\tn := m.Nodes[i]\n\t\tif n.MapKey != nil && n.MapKey.Key != nil {\n\t\t\tif n.MapKey.Key.Path[0].Unbox().ScalarString() == field {\n\t\t\t\tdeleteFromMap(m, n.MapKey)\n\t\t\t} else if n.MapKey.Key.Path[0].Unbox().ScalarString() == \"style\" ||\n\t\t\t\tn.MapKey.Key.Path[0].Unbox().ScalarString() == \"label\" ||\n\t\t\t\tn.MapKey.Key.Path[0].Unbox().ScalarString() == \"icon\" ||\n\t\t\t\tn.MapKey.Key.Path[0].Unbox().ScalarString() == \"source-arrowhead\" ||\n\t\t\t\tn.MapKey.Key.Path[0].Unbox().ScalarString() == \"target-arrowhead\" {","sourceCodeStart":1393,"sourceCodeEnd":1429,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2oracle/edit.go#L1393-L1429","documentation":"During Delete's reserved-key handling, the code walks down the key path from the root object with HasChild for each id segment; if any segment has no matching child, it fails with \"object not found\". This means the key you asked to delete does not resolve to an existing object in the (board's) graph.","triggerScenarios":"deleteReserved — called by Delete with a key whose path contains a segment that doesn't exist as a child object (typo, deleted already, or path too deep), particularly for keys touching reserved contexts.","commonSituations":"Deleting an object twice (second call should be a no-op but this path errors); key strings referencing objects defined only on a different board; glob-generated children addressed by literal name.","solutions":["Verify the object exists (e.g. via d2graph or GetBoardGraph + Root.HasChild) before deleting.","Correct the key path spelling and nesting in the key string.","If the object may already be absent, treat this error as a no-op in your wrapper or check existence first.","Confirm you are targeting the correct boardPath where the object is defined."],"exampleFix":"// before\ng, err := d2oracle.Delete(g, nil, \"x.y.z\") // z doesn't exist\n// after\nif _, ok := g.Root.HasChild([]string{\"x\",\"y\",\"z\"}); ok {\n    g, err = d2oracle.Delete(g, nil, \"x.y.z\")\n}","handlingStrategy":"validation","validationCode":"import \"oss.terrastruct.com/d2/d2graph\"\nif _, ok := g.Root.HasChild(d2graph.Key(mk)); !ok {\n    return nil // nothing to delete; skip the call\n}","typeGuard":"func objectExists(g *d2graph.Graph, ids []string) bool {\n    _, ok := g.Root.HasChild(ids)\n    return ok\n}","tryCatchPattern":"g2, err := d2oracle.Delete(g, boardPath, key)\nif err != nil && strings.Contains(err.Error(), \"object not found\") {\n    return g, nil // treat as idempotent no-op\n}","preventionTips":["Check existence before deleting; deletes are not idempotent here.","Keep key strings in sync with actual object paths.","Recompile after prior structural edits.","Don't address glob-created children by literal path."],"tags":["d2","delete","object-not-found"],"backgroundTag":"object-not-found","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}