d2lang/d2 · critical

Failed to decompress paper texture: %v

Error message

Failed to decompress paper texture: %v

What it means

The WASM build's init decompresses the embedded brotli-computed paper background texture into the package-level paper variable. If compression.DecompressBrotli(paperBr) fails, init panics. This signals corrupt/truncated embedded paper texture data, independent of any user input.

Source

Thrown at d2renderers/d2svg/d2svg_embed_wasm.go:22

import (
	_ "embed"
	"fmt"

	"github.com/d2lang/d2/lib/compression"
)

//go:embed paper.txt.br
var paperBr []byte

var paper string

func init() {
	// Decompress paper texture for WASM builds
	var err error
	paper, err = compression.DecompressBrotli(paperBr)
	if err != nil {
		panic(fmt.Sprintf("Failed to decompress paper texture: %v", err))
	}
}

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Rebuild from a clean checkout to restore a valid embedded paper texture blob
  2. Verify paperBr decompresses standalone (brotli -d) and replace it if corrupt
  3. Re-generate paper.br from the original texture with the project's asset pipeline
  4. Increase the WASM memory limit if failure is allocation-related

Example fix

// before
paper.br // corrupt
git checkout -- d2renderers/d2svg/assets/paper.br && go build
// after
git checkout -- d2renderers/d2svg/assets/paper.br && go build
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the embedded paper asset at build/test time
b, _ := os.ReadFile("d2renderers/d2svg/assets/paper.br")
if _, err := compression.DecompressBrotli(b); err != nil {
    panic("paper.br is corrupt: " + err.Error())
}

Try / catch

// init panic cannot be caught; guard the embedding site instead
paper, err = compression.DecompressBrotli(paperBr)
if err != nil {
    log.Printf("paper texture unavailable: %v", err)
    paper = "" // degrade gracefully, render without texture
}

Prevention

When it happens

Trigger: Process start of a WASM build: init at d2renderers/d2svg/d2svg_embed_wasm.go:22 gets a non-nil error from DecompressBrotli(paperBr) — the embedded asset is invalid or the decompressor fails (e.g. OOM in constrained WASM memory).

Common situations: Corrupted paperBr asset in the repo or after a bad build; asset regenerated with incompatible brotli settings; very low WASM memory limits causing decompression allocation failure.

Related errors


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