{"record":{"id":"872091d5f03414ea","repo":"d2lang/d2","slug":"native-elk-layout-failed-w","errorCode":null,"errorMessage":"native ELK layout failed: %w","messagePattern":"native ELK layout failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2layouts/d2elklayout/layout.go","lineNumber":483,"sourceCode":"\t\telkEdges[edge] = e\n\t}\n\n\tfor k, ports := range ports {\n\t\twidth := elkNodes[k.obj].Width\n\t\tspacing := width / float64(len(ports)+1)\n\t\tfor i, p := range ports {\n\t\t\tp.X = float64(i+1) * spacing\n\t\t}\n\t}\n\n\traw, err := json.Marshal(elkGraph)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tjsonOut, err := elk.LayoutJSON(raw)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"native ELK layout failed: %w\", err)\n\t}\n\n\terr = json.Unmarshal(jsonOut, &elkGraph)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tbyID := make(map[string]*d2graph.Object)\n\twalk(g.Root, nil, func(obj, parent *d2graph.Object) {\n\t\tn := elkNodes[obj]\n\n\t\tparentX := 0.0\n\t\tparentY := 0.0\n\t\tif parent != nil && parent != g.Root {\n\t\t\tparentX = parent.TopLeft.X\n\t\t\tparentY = parent.TopLeft.Y\n\t\t}\n\t\tobj.TopLeft = geo.NewPoint(parentX+n.X, parentY+n.Y)","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2layouts/d2elklayout/layout.go#L465-L501","documentation":"The native ELK layout engine ran elk.LayoutJSON to compute graph layout and the underlying native ELK execution failed. The error wraps the original cause with %w so callers can errors.Is/As into the root failure.","triggerScenarios":"Calling Layout (directly or via DefaultLayout) when the embedded native ELK binary fails to lay out the graph JSON — e.g. the ELK process errors, panics, or the JVM/native runtime is unavailable.","commonSituations":"Missing or corrupted native ELK/JVM dependency on the host; unsupported graph constructs passed to ELK; resource exhaustion (OOM) in the layout process; restricted environments (containers) lacking the runtime.","solutions":["Inspect the wrapped cause with errors.Is/As on the returned error to see the native failure","Verify the ELK native runtime/JVM is installed and reachable in your environment","Switch to another layout engine (e.g. dagre) via the layout option to isolate ELK-specific issues","Reduce graph size/complexity if ELK fails on resource limits"],"exampleFix":"// before\nerr := graph.Layout(ctx, \"elk\")\n// after\nif err := graph.Layout(ctx, \"elk\"); err != nil {\n\tlog.Printf(\"elk failed, falling back: %v\", err)\n\terr = graph.Layout(ctx, \"dagre\")\n}","handlingStrategy":"fallback","validationCode":"if layoutName == \"elk\" {\n\tif _, err := exec.LookPath(\"java\"); err != nil { layoutName = \"dagre\" }\n}","typeGuard":null,"tryCatchPattern":"if err := graph.Layout(ctx, \"elk\"); err != nil {\n\tvar nativeErr *exec.ExitError\n\tif errors.As(err, &nativeErr) {\n\t\treturn errors.Join(ErrELKRuntime, err)\n\t}\n\treturn err\n}","preventionTips":["Ensure the native ELK/JVM runtime is installed in deployment images","Wrap Layout errors with errors.Is/As to surface the wrapped root cause","Benchmark alternative engines (dagre) so a fallback is ready","Monitor memory limits; ELK can OOM on very large graphs"],"tags":["elk","layout","native","layout-engine"],"backgroundTag":"native-layout-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}