{"record":{"id":"b8836094ee5824c2","repo":"d2lang/d2","slug":"failed-to-compile-s-w","errorCode":null,"errorMessage":"failed to compile %s: %w","messagePattern":"failed to compile (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2cli/main.go","lineNumber":420,"sourceCode":"\t\t}\n\t\tboardPath = key.StringIDA()\n\t}\n\n\tctx, cancel := timelib.WithTimeout(ctx, time.Minute*2)\n\tdefer cancel()\n\n\tanimateInterval := *animateIntervalFlag\n\tif outputFormat == GIF && animateInterval == 0 {\n\t\tanimateInterval = 1000\n\t\tms.Log.Debug.Printf(\"GIF export: animate-interval not specified, defaulting to 1000ms\")\n\t}\n\n\t_, written, err := compile(ctx, ms, plugins, nil, layoutFlag, renderOpts, fontFamily, monoFontFamily, animateInterval, inputPath, outputPath, boardPath, noChildren, *bundleFlag, *forceAppendixFlag, pw.Browser, outputFormat, *asciiModeFlag)\n\tif err != nil {\n\t\tif written {\n\t\t\treturn fmt.Errorf(\"failed to fully compile (partial render written) %s: %w\", ms.HumanPath(inputPath), err)\n\t\t}\n\t\treturn fmt.Errorf(\"failed to compile %s: %w\", ms.HumanPath(inputPath), err)\n\t}\n\treturn nil\n}\n\nfunc LayoutResolver(ctx context.Context, ms *xmain.State, plugins []d2plugin.Plugin) func(engine string) (d2graph.LayoutGraph, error) {\n\tcached := make(map[string]d2graph.LayoutGraph)\n\treturn func(engine string) (d2graph.LayoutGraph, error) {\n\t\tif c, ok := cached[engine]; ok {\n\t\t\treturn c, nil\n\t\t}\n\n\t\tplugin, err := d2plugin.FindPlugin(ctx, plugins, engine)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, exec.ErrNotFound) {\n\t\t\t\treturn nil, layoutNotFound(ctx, plugins, engine)\n\t\t\t}\n\t\t\treturn nil, err\n\t\t}","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2cli/main.go#L402-L438","documentation":"Run wraps any error returned by compile() as 'failed to compile <inputPath>: %w' when no partial output was written. The inner error is the real cause (parse error, layout failure, render failure, etc.).","triggerScenarios":"Any failure inside compile() before output was written: D2 syntax errors, unknown layout engine, render/export failures on the given input.","commonSituations":"Invalid D2 script, misconfigured layout key, browser/playwright issues when rendering PNG, or missing fonts.","solutions":["Inspect the wrapped inner error for the exact failing stage","Validate the .d2 input compiles (fix syntax or unknown keywords)","Check the --layout engine name matches an available plugin"],"exampleFix":"// before\nd2 --layout bogus input.d2 out.svg  // failed to compile input.d2: ...\n// after\nd2 --layout elk input.d2 out.svg","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(inputPath); err != nil {\n    return fmt.Errorf(\"input missing: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := d2cli.Run(...); err != nil {\n    if cause := errors.Unwrap(err); cause != nil {\n        log.Printf(\"compile failed for %s: %v\", inputPath, cause)\n    }\n}","preventionTips":["Validate .d2 input files (lint/syntax check) before invoking d2","Ensure the selected --layout engine plugin is registered","Check the errors.Unwrap chain — this message is only a wrapper"],"tags":["go","cli","compile","error-wrapping"],"backgroundTag":"compile-failed-wrapped","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}