{"record":{"id":"38d4a20b39b3dbaa","repo":"sqshq/sampler","slug":"panic-err","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"asset/player.go","lineNumber":41,"sourceCode":"\tif err != nil {\n\t\t// it is expected to fail when some of the system\n\t\t// libraries are not available (e.g. libasound2)\n\t\t// it is not the main functionality of the application,\n\t\t// so we allow startup in no-sound mode\n\t\treturn nil\n\t}\n\n\treturn &AudioPlayer{\n\t\tplayer: player,\n\t\tbeep:   bytes,\n\t}\n}\n\nfunc (a *AudioPlayer) Beep() {\n\n\tdecoder, err := mp3.NewDecoder(NewAssetFile(a.beep))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tif _, err := io.Copy(a.player, decoder); err != nil {\n\t\tpanic(err)\n\t}\n}\n\nfunc (a *AudioPlayer) Close() {\n\t_ = a.player.Close()\n}\n","sourceCodeStart":23,"sourceCodeEnd":52,"githubUrl":"https://github.com/sqshq/sampler/blob/9bc7ba732d31f32a917ad4b5605f00b76ebe0891/asset/player.go#L23-L52","documentation":"AudioPlayer.Beep panics if constructing the mp3.Decoder from the embedded beep asset fails — the bundled MP3 bytes cannot be parsed (truncated, wrong format, or corrupt embedded asset). This is a hard panic by design because a failed beep indicates a broken build embedding of assets.","triggerScenarios":"Calling Execute (which calls Beep) when NewAssetFile(a.beep) yields data that mp3.NewDecoder rejects — e.g. asset embedding changed, file replaced with non-MP3 content, or empty asset.","commonSituations":"Custom builds where go:embed assets were modified or regenerated incorrectly; stripped binaries missing embedded assets; corrupted resource after bundling/packing.","solutions":["Restore the original, valid MP3 asset and rebuild (verify go:embed includes the file)","Regenerate/re-embed the beep asset and confirm mp3.NewDecoder succeeds in a unit test","Wrap Beep with recover() if a missing sound should not crash the app, and log instead of panicking","Verify the binary actually embeds assets (rebuild without -trimpath tricks that might affect embed paths)"],"exampleFix":"// before\nfunc (a *AudioPlayer) Beep() {\n    decoder, err := mp3.NewDecoder(NewAssetFile(a.beep))\n    if err != nil {\n        panic(err)\n    }\n// after\nfunc (a *AudioPlayer) Beep() (err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"beep failed: %v\", r) } }()\n    decoder, derr := mp3.NewDecoder(NewAssetFile(a.beep))\n    if derr != nil { return derr }","handlingStrategy":"try-catch","validationCode":"// pre-validate embedded asset\nf, err := asset.Asset(\"beep.mp3\")\nif err != nil || len(f) < 4 { audioDisabled = true }","typeGuard":"func audioAvailable() bool { data, err := asset.Asset(\"beep.mp3\"); return err == nil && len(data) > 0 }","tryCatchPattern":"func safeBeep(p *asset.AudioPlayer) {\n    defer func() { if r := recover(); r != nil { log.Printf(\"beep skipped: %v\", r) } }()\n    p.Beep()\n}","preventionTips":["Add a startup self-test that decodes the beep asset once","Keep embedded MP3 assets intact through build/bundle steps","Treat sound as optional and recover from panics"],"tags":["go","panic","audio","mp3","embedded-assets"],"backgroundTag":"invalid-argument-format","analyzedSha":"9bc7ba732d31f32a917ad4b5605f00b76ebe0891","analyzedAt":"2026-09-06T08:38:02.595Z","contentChangedAt":"2026-09-06T08:38:02.595Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}