flxzt/rnote · error

Failed to init audioplayer. file

Error message

Failed to init audioplayer. file `{resource_path:?}` does not exist.

What it means

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.

Solutions

  1. Verify the file exists at the exact resource_path before constructing the audioplayer (fs::metadata or Path::exists).
  2. Resolve relative paths against the correct base directory (document dir, data dir) and use canonical paths.
  3. Check that the resource is actually bundled/shipped with the app (flatpak/appimage packaging often omits user data).
  4. Handle the Err gracefully in the caller and surface a user-facing 'missing audio file' message instead of failing the whole document load.

Example fix

// before
let player = AudioSourcePlayer::new_init(&path, ...).await?;
// after
if !path.exists() {
    eprintln!("skipping missing audio file: {:?}", path);
} else {
    let player = AudioSourcePlayer::new_init(&path, ...).await?;
}
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_audio_exists(path: &std::path::Path) -> Result<(), String> {
    if path.is_file() { Ok(()) } else { Err(format!("audio file missing: {:?}", path)) }
}

Type guard

fn audio_file_exists(p: &std::path::Path) -> bool {
    p.is_file()
}

Try / catch

match AudioSourcePlayer::new_init(&path, ...).await {
    Ok(p) => p,
    Err(e) if e.to_string().contains("does not exist") => {
        log::warn!("skipping missing audio: {e}");
        Default::default()
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08). Data as JSON: /api/errors/eb0bcf9e27157cfb. Report an issue: GitHub.

Appendix: source

Thrown at crates/rnote-engine/src/audioplayer.rs:217

    mut resource_path: PathBuf,
    sound_name: &str,
    ending: &str,
) -> anyhow::Result<Buffered<Decoder<File>>> {
    resource_path.push(format!("{sound_name}.{ending}"));

    if resource_path.exists() {
        let buffered =
            rodio::Decoder::new(File::open(resource_path.clone()).with_context(|| {
                anyhow::anyhow!("Open file for path {:?} failed", resource_path,)
            })?)?
            .buffered();

        // initialize the buffer
        buffered.clone().for_each(|_| {});

        Ok(buffered)
    } else {
        Err(anyhow::anyhow!(
            "Failed to init audioplayer. file `{resource_path:?}` does not exist."
        ))
    }
}

View on GitHub (pinned to bbc5354502)