{"record":{"id":"641b7e290222357d","repo":"d2lang/d2","slug":"code-snippet-formatter-svg-not-found","errorCode":null,"errorMessage":"code snippet formatter \"svg\" not found","messagePattern":"code snippet formatter \"svg\" not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2renderers/d2svg/d2svg.go","lineNumber":2150,"sourceCode":"\t\t\t\ttargetShape.Underline,\n\t\t\t))\n\t\t} else if targetShape.Language != \"\" {\n\t\t\tlexer := lexers.Get(targetShape.Language)\n\t\t\tif lexer == nil {\n\t\t\t\tlexer = lexers.Fallback\n\t\t\t}\n\t\t\tfor _, isLight := range []bool{true, false} {\n\t\t\t\ttheme := \"github\"\n\t\t\t\tif !isLight {\n\t\t\t\t\ttheme = \"catppuccin-mocha\"\n\t\t\t\t}\n\t\t\t\tstyle := styles.Get(theme)\n\t\t\t\tif style == nil {\n\t\t\t\t\treturn labelMask, errors.New(`code snippet style \"github\" not found`)\n\t\t\t\t}\n\t\t\t\tformatter := formatters.Get(\"svg\")\n\t\t\t\tif formatter == nil {\n\t\t\t\t\treturn labelMask, errors.New(`code snippet formatter \"svg\" not found`)\n\t\t\t\t}\n\t\t\t\titerator, err := lexer.Tokenise(nil, targetShape.Label)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn labelMask, err\n\t\t\t\t}\n\n\t\t\t\tsvgStyles := styleToSVG(style)\n\t\t\t\tclass := \"light-code\"\n\t\t\t\tif !isLight {\n\t\t\t\t\tclass = \"dark-code\"\n\t\t\t\t}\n\t\t\t\tvar fontSize string\n\t\t\t\tif targetShape.FontSize != d2fonts.FONT_SIZE_M {\n\t\t\t\t\tfontSize = fmt.Sprintf(` style=\"font-size:%v\"`, targetShape.FontSize)\n\t\t\t\t}\n\t\t\t\tfmt.Fprintf(writer, `<g transform=\"translate(%f %f)\" class=\"%s\"%s>`,\n\t\t\t\t\tbox.TopLeft.X, box.TopLeft.Y, class, fontSize,\n\t\t\t\t)","sourceCodeStart":2132,"sourceCodeEnd":2168,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2renderers/d2svg/d2svg.go#L2132-L2168","documentation":"After obtaining the highlighting style for a code-snippet shape label, d2svg fetches the chroma 'svg' formatter to emit highlighted markup. If formatters.Get(\"svg\") returns nil, the formatter registry lacks the SVG formatter and drawShape fails with this error.","triggerScenarios":"Rendering a shape with a code-snippet label via d2svg.Render when the chroma formatters registry does not contain 'svg' (formatters.Get returns nil).","commonSituations":"Custom builds that blank-import only chroma styles but not formatters; chroma version changes; vendoring that drops the formatters package.","solutions":["Blank-import github.com/alecthomas/chroma/v2/formatters so embedded formatters (including svg) register","Verify the installed chroma version provides the svg formatter; upgrade or pin chroma","Ensure vendor/build steps do not remove the formatters package"],"exampleFix":"// before\nimport _ \"github.com/alecthomas/chroma/v2/styles\"\n// after\nimport (\n    _ \"github.com/alecthomas/chroma/v2/formatters\"\n    _ \"github.com/alecthomas/chroma/v2/styles\"\n)","handlingStrategy":"fallback","validationCode":"if chromaformatters.Get(\"svg\") == nil {\n    return errors.New(\"chroma svg formatter unavailable\")\n}","typeGuard":"func chromaFormatterAvailable(name string) bool {\n    return chromaformatters.Get(name) != nil\n}","tryCatchPattern":"out, err := d2svg.Render(diagram, opts)\nif err != nil && strings.Contains(err.Error(), \"code snippet formatter\") {\n    // retry after registering formatters or render labels unhighlighted\n}","preventionTips":["Blank-import github.com/alecthomas/chroma/v2/formatters","Check vendored chroma retains the formatters package","Add a registry availability check at startup"],"tags":["svg","rendering","syntax-highlighting"],"backgroundTag":"chroma-formatter-not-found","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}