d2lang/d2 · error

code snippet style "github" not found

Error message

code snippet style "github" not found

What it means

When drawing a connection whose label is rendered as a code snippet, d2svg looks up a syntax-highlighting style from the embedded chroma style registry ('github' for light, 'catppuccin-mocha' for dark). If the style is missing from the registry (e.g. build without embedded styles or an unexpected registry state), drawConnection returns this error and the connection label mask cannot be produced.

Source

Thrown at d2renderers/d2svg/d2svg.go:1286

				connection.LabelHeight,
				connection.GetFontColor(),
				connection.Fill,
				connection.Link != "",
				connection.Underline,
			))
		} else if connection.Language != "" {
			lexer := lexers.Get(connection.Language)
			if lexer == nil {
				lexer = lexers.Fallback
			}
			for _, isLight := range []bool{true, false} {
				theme := "github"
				if !isLight {
					theme = "catppuccin-mocha"
				}
				style := styles.Get(theme)
				if style == nil {
					return labelMask, errors.New(`code snippet style "github" not found`)
				}
				iterator, err := lexer.Tokenise(nil, connection.Label)
				if err != nil {
					return labelMask, err
				}

				svgStyles := styleToSVG(style)
				class := "light-code"
				if !isLight {
					class = "dark-code"
				}
				var fontSize string
				if connection.FontSize != d2fonts.FONT_SIZE_M {
					fontSize = fmt.Sprintf(` style="font-size:%v"`, connection.FontSize)
				}
				fmt.Fprintf(writer, `<g transform="translate(%f %f)" class="%s"%s>`,
					labelTL.X, labelTL.Y, class, fontSize,
				)

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Ensure the chroma dependency includes embedded styles (import _ 'github.com/alecthomas/chroma/v2/styles' side-effect package)
  2. Verify the chroma version used provides 'github' and 'catppuccin-mocha' styles; upgrade or pin a compatible version
  3. Check that build tooling (e.g. go mod vendor) did not strip embedded style assets

Example fix

// before
import "github.com/alecthomas/chroma/v2"
// after (ensure styles registry is populated)
import _ "github.com/alecthomas/chroma/v2/styles"
Defensive patterns

Strategy: fallback

Validate before calling

if chromastyles.Get("github") == nil || chromastyles.Get("catppuccin-mocha") == nil {
    return errors.New("chroma styles registry missing required themes")
}

Type guard

func hasChromaStyle(name string) bool {
    return chromastyles.Get(name) != nil
}

Try / catch

labelMask, err := d2svg.Render(diagram, opts)
if err != nil && strings.Contains(err.Error(), "code snippet style") {
    // fall back to plain-text labels or fix embedded style imports
}

Prevention

When it happens

Trigger: Rendering a diagram containing a connection (edge) with a code/markdown label via d2svg.Render, where styles.Get("github") or styles.Get("catppuccin-mocha") returns nil — i.e. the chroma styles registry does not contain the embedded theme.

Common situations: Custom or stripped-down builds of chroma that exclude embedded styles; vendoring/importing a different chroma version where style names changed; mis-assembled binaries missing embedded assets.

Related errors


AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31). Data as JSON: /api/errors/7cd0ba78cb09499d. Report an issue: GitHub.