{"record":{"id":"84eb61597d7f7377","repo":"d2lang/d2","slug":"object-s-has-near-set-to-another-object-but","errorCode":null,"errorMessage":"Object \"%s\" has \"near\" set to another object, but layout engine \"%s\" only supports constant values for \"near\". See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.","messagePattern":"Object \"(.+?)\" has \"near\" set to another object, but layout engine \"(.+?)\" only supports constant values for \"near\"\\. See https://d2lang\\.com/tour/layouts/#layout-specific-functionality for more\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2plugin/plugin_features.go","lineNumber":55,"sourceCode":"\n\tfor _, obj := range g.Objects {\n\t\tif obj.Top != nil || obj.Left != nil {\n\t\t\tif _, ok := featureMap[TOP_LEFT]; !ok {\n\t\t\t\treturn fmt.Errorf(`Object \"%s\" has attribute \"top\" and/or \"left\" set, but layout engine \"%s\" does not support locked positions. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)\n\t\t\t}\n\t\t}\n\t\tif (obj.WidthAttr != nil || obj.HeightAttr != nil) &&\n\t\t\tlen(obj.ChildrenArray) > 0 && !obj.IsGridDiagram() {\n\t\t\tif _, ok := featureMap[CONTAINER_DIMENSIONS]; !ok {\n\t\t\t\treturn fmt.Errorf(`Object \"%s\" has attribute \"width\" and/or \"height\" set, but layout engine \"%s\" does not support dimensions set on containers. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)\n\t\t\t}\n\t\t}\n\n\t\tif obj.NearKey != nil {\n\t\t\t_, isKey := g.Root.HasChild(d2graph.Key(obj.NearKey))\n\t\t\tif isKey {\n\t\t\t\tif _, ok := featureMap[NEAR_OBJECT]; !ok {\n\t\t\t\t\treturn fmt.Errorf(`Object \"%s\" has \"near\" set to another object, but layout engine \"%s\" only supports constant values for \"near\". See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif _, ok := featureMap[DESCENDANT_EDGES]; !ok {\n\t\tfor _, e := range g.Edges {\n\t\t\t// descendant edges are ok in sequence diagrams\n\t\t\tif e.Src.OuterSequenceDiagram() != nil || e.Dst.OuterSequenceDiagram() != nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif !e.Src.IsContainer() && !e.Dst.IsContainer() {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif e.Src == e.Dst {\n\t\t\t\treturn fmt.Errorf(`Connection \"%s\" is a self loop on a container, but layout engine \"%s\" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, e.AbsID(), info.Name)\n\t\t\t}\n\t\t\tif e.Src.IsDescendantOf(e.Dst) || e.Dst.IsDescendantOf(e.Src) {\n\t\t\t\treturn fmt.Errorf(`Connection \"%s\" goes from a container to a descendant, but layout engine \"%s\" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, e.AbsID(), info.Name)","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2plugin/plugin_features.go#L37-L73","documentation":"FeatureSupportCheck rejects graphs where an object's near is set to another object's key while the layout engine only supports constant near values (no NEAR_OBJECT feature).","triggerScenarios":"obj.NearKey is a key that resolves to another object in the graph root (g.Root.HasChild succeeds) and the engine lacks NEAR_OBJECT.","commonSituations":"Writing `b.near: a` to position b relative to a while using dagre, which only supports near: top-center style constants.","solutions":["Switch to ELK, which supports object-relative near","Remove the near attribute and use constant positions","Reorder declaration or restructure containers to get desired placement"],"exampleFix":"// before\nb.near: a\n// after\nb.near: top-center // or use layout: elk","handlingStrategy":"validation","validationCode":"for _, obj := range g.Objects {\n\tif obj.NearKey != nil && engineName != \"elk\" {\n\t\tif isKey, _ := g.Root.HasChild(d2graph.Key(obj.NearKey)); isKey {\n\t\t\t// object-near unsupported; rewrite\n\t\t}\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := engine.FeatureSupportCheck(ctx, g); err != nil {\n\treturn fmt.Errorf(\"near-object unsupported: %w\", err)\n}","preventionTips":["Use constant near values (top-center etc.) with non-ELK engines","Keep object-relative positioning restricted to ELK diagrams","Validate diagrams with FeatureSupportCheck before layout"],"tags":["layout","feature-check","near"],"backgroundTag":"layout-feature-unsupported","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}