{"record":{"id":"1fa92319110b5182","repo":"d2lang/d2","slug":"failed-to-decompress-paper-texture-v","errorCode":null,"errorMessage":"Failed to decompress paper texture: %v","messagePattern":"Failed to decompress paper texture: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"d2renderers/d2svg/d2svg_embed_wasm.go","lineNumber":22,"sourceCode":"\nimport (\n\t_ \"embed\"\n\t\"fmt\"\n\n\t\"github.com/d2lang/d2/lib/compression\"\n)\n\n//go:embed paper.txt.br\nvar paperBr []byte\n\nvar paper string\n\nfunc init() {\n\t// Decompress paper texture for WASM builds\n\tvar err error\n\tpaper, err = compression.DecompressBrotli(paperBr)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Failed to decompress paper texture: %v\", err))\n\t}\n}\n","sourceCodeStart":4,"sourceCodeEnd":25,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2renderers/d2svg/d2svg_embed_wasm.go#L4-L25","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Rebuild from a clean checkout to restore a valid embedded paper texture blob","Verify paperBr decompresses standalone (brotli -d) and replace it if corrupt","Re-generate paper.br from the original texture with the project's asset pipeline","Increase the WASM memory limit if failure is allocation-related"],"exampleFix":"// before\npaper.br // corrupt\ngit checkout -- d2renderers/d2svg/assets/paper.br && go build\n// after\ngit checkout -- d2renderers/d2svg/assets/paper.br && go build","handlingStrategy":"try-catch","validationCode":"// Validate the embedded paper asset at build/test time\nb, _ := os.ReadFile(\"d2renderers/d2svg/assets/paper.br\")\nif _, err := compression.DecompressBrotli(b); err != nil {\n    panic(\"paper.br is corrupt: \" + err.Error())\n}","typeGuard":null,"tryCatchPattern":"// init panic cannot be caught; guard the embedding site instead\npaper, err = compression.DecompressBrotli(paperBr)\nif err != nil {\n    log.Printf(\"paper texture unavailable: %v\", err)\n    paper = \"\" // degrade gracefully, render without texture\n}","preventionTips":["CI: decompress-check every embedded brotli asset","Allocate sufficient WASM memory for asset decompression","Restore assets via git rather than manual edits","Regenerate paper.br only with the project asset pipeline"],"tags":["go","panic","init","wasm","brotli","embedded-assets"],"backgroundTag":"brotli-decompression-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}