{"record":{"id":"878f698d19c2c4a6","repo":"d2lang/d2","slug":"failed-to-decompress-sourcesanspro-regular-v","errorCode":null,"errorMessage":"Failed to decompress SourceSansPro-Regular: %v","messagePattern":"Failed to decompress SourceSansPro-Regular: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"d2renderers/d2fonts/d2fonts_embed_wasm.go","lineNumber":55,"sourceCode":"\n//go:embed encoded/SourceCodePro-Italic.txt.br\nvar sourceCodeProItalicBr []byte\n\n//go:embed encoded/FuzzyBubbles-Regular.txt.br\nvar fuzzyBubblesRegularBr []byte\n\n//go:embed encoded/FuzzyBubbles-Bold.txt.br\nvar fuzzyBubblesBoldBr []byte\n\n//go:embed ttf/*\nvar fontFacesFS embed.FS\n\nfunc init() {\n\tFontEncodings = syncmap.New[Font, string]()\n\n\t// Decompress and register SourceSansPro fonts\n\tif str, err := compression.DecompressBrotli(sourceSansProRegularBr); err != nil {\n\t\tpanic(fmt.Sprintf(\"Failed to decompress SourceSansPro-Regular: %v\", err))\n\t} else {\n\t\tFontEncodings.Set(Font{Family: SourceSansPro, Style: FONT_STYLE_REGULAR}, str)\n\t}\n\n\tif str, err := compression.DecompressBrotli(sourceSansProBoldBr); err != nil {\n\t\tpanic(fmt.Sprintf(\"Failed to decompress SourceSansPro-Bold: %v\", err))\n\t} else {\n\t\tFontEncodings.Set(Font{Family: SourceSansPro, Style: FONT_STYLE_BOLD}, str)\n\t}\n\n\tif str, err := compression.DecompressBrotli(sourceSansProSemiboldBr); err != nil {\n\t\tpanic(fmt.Sprintf(\"Failed to decompress SourceSansPro-Semibold: %v\", err))\n\t} else {\n\t\tFontEncodings.Set(Font{Family: SourceSansPro, Style: FONT_STYLE_SEMIBOLD}, str)\n\t}\n\n\tif str, err := compression.DecompressBrotli(sourceSansProItalicBr); err != nil {\n\t\tpanic(fmt.Sprintf(\"Failed to decompress SourceSansPro-Italic: %v\", err))","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2renderers/d2fonts/d2fonts_embed_wasm.go#L37-L73","documentation":"In the WASM build, SourceSansPro Regular font data is embedded brotli-compressed and decompressed in a package init(). If compression.DecompressBrotli fails, init panics with this message, so the process/instance fails to start. It means the embedded font blob is corrupt or the brotli decoder failed.","triggerScenarios":"Any use of the wasm d2fonts package where the embedded sourceSansProRegularBr bytes fail brotli decompression — typically a broken build/embed step (wrong or empty asset embedded) rather than runtime user input.","commonSituations":"Custom wasm builds where the fonts_embed assets weren't generated correctly; truncated embedded assets after aggressive bundler minification; mismatched compression tooling versions when regenerating the .br files.","solutions":["Rebuild the wasm bundle ensuring d2fonts embedded assets are generated/embedded intact","Verify the .br asset bytes are non-empty and valid brotli (decompress standalone with a brotli CLI)","Regenerate the brotli-compressed font files with the same toolchain the project uses","If the panic persists in a custom build, diff your build against upstream d2's wasm build script"],"exampleFix":"// before (custom build)\nrm d2renderers/d2fonts/*.br && git checkout -- d2renderers/d2fonts/*.br\nmake wasm\n// after: init() decompresses without panic","handlingStrategy":"fallback","validationCode":"if str, err := compression.DecompressBrotli(sourceSansProRegularBr); err != nil {\n    log.Printf(\"font init failed: %v; falling back to defaults\", err)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Printf(\"d2fonts init panic: %v\", r)\n        useSystemFonts = true\n    }\n}() // note: panics in init() are fatal in Go; the real guard is a correct build","preventionTips":["Never modify embedded .br font assets by hand","Build wasm artifacts with the project's official build script","Smoke-test the wasm module immediately after instantiation to surface init panics in CI","Verify embedded assets are present and byte-identical to upstream in release builds"],"tags":["wasm","fonts","brotli","init-panic"],"backgroundTag":"brotli-decompression-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}