{"record":{"id":"eb0bcf9e27157cfb","repo":"flxzt/rnote","slug":"failed-to-init-audioplayer-file-resource-path","errorCode":null,"errorMessage":"Failed to init audioplayer. file `{resource_path:?}` does not exist.","messagePattern":"Failed to init audioplayer\\. file `(.+?)` does not exist\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/audioplayer.rs","lineNumber":217,"sourceCode":"    mut resource_path: PathBuf,\n    sound_name: &str,\n    ending: &str,\n) -> anyhow::Result<Buffered<Decoder<File>>> {\n    resource_path.push(format!(\"{sound_name}.{ending}\"));\n\n    if resource_path.exists() {\n        let buffered =\n            rodio::Decoder::new(File::open(resource_path.clone()).with_context(|| {\n                anyhow::anyhow!(\"Open file for path {:?} failed\", resource_path,)\n            })?)?\n            .buffered();\n\n        // initialize the buffer\n        buffered.clone().for_each(|_| {});\n\n        Ok(buffered)\n    } else {\n        Err(anyhow::anyhow!(\n            \"Failed to init audioplayer. file `{resource_path:?}` does not exist.\"\n        ))\n    }\n}\n","sourceCodeStart":199,"sourceCodeEnd":222,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/audioplayer.rs#L199-L222","documentation":"This error is thrown by load_sound_from_path when the audio file path given to the audioplayer does not exist on disk. The player cannot build an audio buffer from a missing resource, so initialization fails early with an explicit message naming the path.","triggerScenarios":"Calling the audioplayer constructor path (new_init -> load_sound_from_path) with a resource_path that points to a non-existent file, e.g. a typo'd path, a file deleted between selection and load, or a relative path resolved against the wrong working directory.","commonSituations":"Loading a sound recording whose backing file was moved or cleaned up, restoring old .rnote documents that reference audio files no longer present, packaging apps that forget to bundle audio resources, or passing unsanitized user paths on a different filesystem.","solutions":["Verify the file exists at the exact resource_path before constructing the audioplayer (fs::metadata or Path::exists).","Resolve relative paths against the correct base directory (document dir, data dir) and use canonical paths.","Check that the resource is actually bundled/shipped with the app (flatpak/appimage packaging often omits user data).","Handle the Err gracefully in the caller and surface a user-facing 'missing audio file' message instead of failing the whole document load."],"exampleFix":"// before\nlet player = AudioSourcePlayer::new_init(&path, ...).await?;\n// after\nif !path.exists() {\n    eprintln!(\"skipping missing audio file: {:?}\", path);\n} else {\n    let player = AudioSourcePlayer::new_init(&path, ...).await?;\n}","handlingStrategy":"validation","validationCode":"fn ensure_audio_exists(path: &std::path::Path) -> Result<(), String> {\n    if path.is_file() { Ok(()) } else { Err(format!(\"audio file missing: {:?}\", path)) }\n}","typeGuard":"fn audio_file_exists(p: &std::path::Path) -> bool {\n    p.is_file()\n}","tryCatchPattern":"match AudioSourcePlayer::new_init(&path, ...).await {\n    Ok(p) => p,\n    Err(e) if e.to_string().contains(\"does not exist\") => {\n        log::warn!(\"skipping missing audio: {e}\");\n        Default::default()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always stat the path before constructing the player","Store audio as attachments with checksums and verify presence on load","Resolve relative paths against the document's directory","Handle missing audio gracefully so one bad file cannot block document load"],"tags":["rust","filesystem","audio","path"],"backgroundTag":"file-not-found","analyzedSha":"bbc5354502ba2fc83eec2670b535348825e679a6","analyzedAt":"2026-09-08T13:20:33.747Z","contentChangedAt":"2026-09-08T13:20:33.747Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}