d2lang/d2 · critical

Failed to decompress SourceCodePro-Italic: %v

Error message

Failed to decompress SourceCodePro-Italic: %v

What it means

At WASM build init, d2fonts decompresses embedded Brotli-compressed font blobs and registers them in FontEncodings. If compression.DecompressBrotli fails for the embedded SourceCodePro-Italic blob, init panics with this message. It means the embedded asset is corrupt/truncated or the brotli decompressor failed.

Source

Thrown at d2renderers/d2fonts/d2fonts_embed_wasm.go:98

		panic(fmt.Sprintf("Failed to decompress SourceCodePro-Regular: %v", err))
	} else {
		FontEncodings.Set(Font{Family: SourceCodePro, Style: FONT_STYLE_REGULAR}, str)
	}

	if str, err := compression.DecompressBrotli(sourceCodeProBoldBr); err != nil {
		panic(fmt.Sprintf("Failed to decompress SourceCodePro-Bold: %v", err))
	} else {
		FontEncodings.Set(Font{Family: SourceCodePro, Style: FONT_STYLE_BOLD}, str)
	}

	if str, err := compression.DecompressBrotli(sourceCodeProSemiboldBr); err != nil {
		panic(fmt.Sprintf("Failed to decompress SourceCodePro-Semibold: %v", err))
	} else {
		FontEncodings.Set(Font{Family: SourceCodePro, Style: FONT_STYLE_SEMIBOLD}, str)
	}

	if str, err := compression.DecompressBrotli(sourceCodeProItalicBr); err != nil {
		panic(fmt.Sprintf("Failed to decompress SourceCodePro-Italic: %v", err))
	} else {
		FontEncodings.Set(Font{Family: SourceCodePro, Style: FONT_STYLE_ITALIC}, str)
	}

	// Decompress and register FuzzyBubbles fonts
	if str, err := compression.DecompressBrotli(fuzzyBubblesRegularBr); err != nil {
		panic(fmt.Sprintf("Failed to decompress FuzzyBubbles-Regular: %v", err))
	} else {
		FontEncodings.Set(Font{Family: HandDrawn, Style: FONT_STYLE_REGULAR}, str)
		// HandDrawn has no italic, so reuse regular
		FontEncodings.Set(Font{Family: HandDrawn, Style: FONT_STYLE_ITALIC}, str)
	}

	if str, err := compression.DecompressBrotli(fuzzyBubblesBoldBr); err != nil {
		panic(fmt.Sprintf("Failed to decompress FuzzyBubbles-Bold: %v", err))
	} else {
		FontEncodings.Set(Font{Family: HandDrawn, Style: FONT_STYLE_BOLD}, str)
		// HandDrawn has no semibold, so reuse bold

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Rebuild the binary/WASM module from a clean checkout so the embedded brotli assets are regenerated
  2. Verify the sourceCodeProItalicBr embedded blob is a valid, uncorrupted .br file (test-decompress it independently)
  3. Replace or re-download the corrupted SourceCodePro-Italic .br asset, then rebuild
  4. Ensure the brotli decompression dependency version matches the compression level used to produce the assets

Example fix

// before (corrupted blob in source tree)
fonts/sourceCodePro-Italic.ttf.br // truncated file
// after
curl -O <valid sourceCodePro-Italic.ttf.br> && go build
Defensive patterns

Strategy: try-catch

Validate before calling

// Go has no try before init; validate assets at build time:
// go run ./tools/verify-brotli-assets d2renderers/d2fonts/assets/sourceCodePro-Italic.ttf.br
func validBrotli(b []byte) bool { _, err := compression.DecompressBrotli(b); return err == nil }

Try / catch

// Go: init panics cannot be caught; guard at embedding site
func mustDecomp(b []byte, name string) string {
    s, err := compression.DecompressBrotli(b)
    if err != nil { log.Fatalf("font asset %s invalid: %v", name, err) }
    return s
}

Prevention

When it happens

Trigger: Process start of a WASM build: init in d2renderers/d2fonts/d2fonts_embed_wasm.go:98 calls compression.DecompressBrotli(sourceCodeProItalicBr) and the returned err is non-nil — the embedded brotli bytes are corrupted, truncated, or were replaced with invalid data at build time.

Common situations: Custom builds where embedded font assets were regenerated incorrectly; file corruption or truncation of the .br assets; build tooling (go:embed/generate steps) producing bad blobs; memory pressure in tiny WASM environments causing decompression failure.

Related errors


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