d2lang/d2 · critical

Failed to decompress SourceCodePro-Regular: %v

Error message

Failed to decompress SourceCodePro-Regular: %v

What it means

init()-time panic in the wasm d2fonts package when the embedded brotli-compressed SourceCodePro Regular font fails to decompress. Like the other embedded fonts, failure here aborts module initialization before any rendering can occur.

Source

Thrown at d2renderers/d2fonts/d2fonts_embed_wasm.go:80

	} else {
		FontEncodings.Set(Font{Family: SourceSansPro, Style: FONT_STYLE_BOLD}, str)
	}

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

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

	// Decompress and register SourceCodePro fonts
	if str, err := compression.DecompressBrotli(sourceCodeProRegularBr); err != nil {
		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))

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Verify sourceCodeProRegularBr decompresses with a standalone tool
  2. Regenerate the .br asset using the project's embed script
  3. Rebuild wasm from a clean checkout of d2
  4. Align brotli tool versions with the project's documented toolchain
Defensive patterns

Strategy: fallback

Validate before calling

if _, err := compression.DecompressBrotli(sourceCodeProRegularBr); err != nil {
    return fmt.Errorf("broken embedded SourceCodePro-Regular asset: %w", err)
}

Prevention

When it happens

Trigger: Package init of the wasm build when compression.DecompressBrotli(sourceCodeProRegularBr) returns an error due to corrupt/empty/mismatched embedded asset.

Common situations: Faulty asset generation in the wasm build pipeline; truncated embedded files; version mismatch between brotli compressor and the Go brotli decompressor.

Related errors


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