{"record":{"id":"d3bde3ac0b3d1b07","repo":"d2lang/d2","slug":"failed-to-scompile-w","errorCode":null,"errorMessage":"failed to %scompile: %w","messagePattern":"failed to (.+?)compile: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2cli/watch.go","lineNumber":453,"sourceCode":"\t\t\t\tcontinue\n\t\t\t}\n\t\t\tw.pw = newPW\n\t\t}\n\n\t\tfs := trackedFS{}\n\t\tw.boardpathMu.Lock()\n\t\tvar boardPath []string\n\t\tif w.boardPath != \"\" {\n\t\t\tboardPath = strings.Split(w.boardPath, string(os.PathSeparator))\n\t\t}\n\t\tsvg, _, err := compile(ctx, w.ms, w.plugins, &fs, w.layout, w.renderOpts, w.fontFamily, w.monoFontFamily, w.animateInterval, w.inputPath, w.outputPath, boardPath, false, w.bundle, w.forceAppendix, w.pw.Browser, w.outputFormat, w.asciiMode)\n\t\tw.boardpathMu.Unlock()\n\t\terrs := \"\"\n\t\tif err != nil {\n\t\t\tif len(svg) > 0 {\n\t\t\t\terr = fmt.Errorf(\"failed to fully %scompile (rendering partial svg): %w\", recompiledPrefix, err)\n\t\t\t} else {\n\t\t\t\terr = fmt.Errorf(\"failed to %scompile: %w\", recompiledPrefix, err)\n\t\t\t}\n\t\t\terrs = err.Error()\n\t\t\tw.ms.Log.Error.Print(errs)\n\t\t}\n\t\terr = w.replaceWatchList(ctx, fs.opened)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tw.broadcast(&compileResult{\n\t\t\tSVG:   string(svg),\n\t\t\tScale: w.renderOpts.Scale,\n\t\t\tErr:   errs,\n\t\t})\n\n\t\tif firstCompile {\n\t\t\tfirstCompile = false\n\t\t\turl := fmt.Sprintf(\"http://%s\", w.l.Addr())","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2cli/watch.go#L435-L471","documentation":"When compile() fails without producing any SVG, watch wraps the error as \"failed to <re>compile\", preserving the underlying cause. The prefix is \"compile\" on first compile and \"recompile\" on subsequent watch triggers.","triggerScenarios":"compileLoop calls compile() and it returns err with an empty svg — e.g. parse errors, invalid style values, layout errors, or missing resources in the .d2 input.","commonSituations":"Editing a .d2 file in watch mode and introducing a syntax error, using an invalid style key/value, or a plugin/layout failure.","solutions":["Read the wrapped cause after the colon — it identifies the exact line/key","Fix the syntax or semantic error in the .d2 file","Validate the file with a one-shot `d2 file.d2` run (no watch) to see full errors"],"exampleFix":"// before\nx.style.bogus: 3\n// after\nx.style.border-radius: 3","handlingStrategy":"try-catch","validationCode":"// validate before watching:\n// d2 file.d2 /tmp/out.svg   # surfaces parse/semantic errors immediately","typeGuard":null,"tryCatchPattern":"if strings.Contains(errStr, \"failed to compile\") {\n\tcause := strings.SplitN(errStr, \": \", 2)\n\t// cause[1] holds the precise line/key error\n}","preventionTips":["Read the text after the final colon — it pinpoints the real error","Use an editor with d2-lsp/syntax highlighting","Run d2 once without --watch to validate"],"tags":["watch-mode","compile","d2-syntax"],"backgroundTag":"diagram-compile-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}