tonhowtf/omniget · error · anyhow::Error

anyhow!(e.to_string())

Error message

anyhow!(e.to_string())

What it means

This is a generic wrapper: lofty::read_from_path() failed to parse the audio file, and the library converts the lofty ParsingError into an anyhow error by stringifying it. It means the file could not be opened or decoded as a tagged audio format by the lofty crate — not a problem with the tags being edited, but with reading the file's existing metadata/container at all.

Solutions

  1. Confirm the file is a supported audio format (MP3, FLAC, M4A, OGG, WAV, etc.) and plays in a normal player.
  2. Re-obtain or re-download the file if it is truncated or corrupt (check size > 0 and intact header).
  3. Improve the error by using with_context to keep the path alongside lofty's message: .map_err(|e| anyhow!("falha ao ler {}: {e}", path)).
  4. Match on lofty's error kind to give distinct messages for unsupported vs malformed input instead of e.to_string().

Example fix

// before
let mut tagged = lofty::read_from_path(path).map_err(|e| anyhow!(e.to_string()))?;
// after
let mut tagged = lofty::read_from_path(path)
    .with_context(|| format!("falha ao ler tags de {}: {e}", path))?;
Defensive patterns

Strategy: try-catch

Validate before calling

fn readable_audio(path: &str) -> bool {
    std::path::Path::new(path).is_file() && std::fs::metadata(path).map(|m| m.len() > 0).unwrap_or(false)
}

Try / catch

match lofty::read_from_path(path) {
    Ok(tagged) => /* editar tags */,
    Err(e) => eprintln!("arquivo de áudio ilegível/corrompido ({path}): {e}"),
}

Prevention

When it happens

Trigger: Calling the tag-editing function on a path whose file lofty cannot parse: unsupported container, corrupted headers, zero-byte or truncated file, or a non-audio file passed as path.

Common situations: Pointing the tool at a partially downloaded MP3, a DRM-protected or unusual-format file, a renamed non-audio file, or a path that now points to an empty file.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/5239bd5a1b00711a. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/audio_tag.rs:1238

        diffs: diffs.to_vec(),
        cover: None,
        unsupported: Vec::new(),
        written: false,
        backup: None,
        error: None,
    };

    let cover_bytes = if let Some(cover) = opts.cover_path.as_deref().filter(|s| !s.is_empty()) {
        let data =
            std::fs::read(cover).with_context(|| format!("não consegui ler a capa em {cover}"))?;
        let mime =
            mime_of(&data).ok_or_else(|| anyhow!("a capa {cover} não é PNG, JPEG, GIF ou BMP"))?;
        Some((data, mime))
    } else {
        None
    };

    let mut tagged = lofty::read_from_path(path).map_err(|e| anyhow!(e.to_string()))?;
    let tag_type = tagged.primary_tag_type();
    if tagged.primary_tag_mut().is_none() {
        tagged.insert_tag(Tag::new(tag_type));
    }
    let tag = tagged
        .primary_tag_mut()
        .ok_or_else(|| anyhow!("o formato não aceita a tag {tag_type:?}"))?;

    let before_cover = tag.pictures().len();
    let before_bytes: u64 = tag.pictures().iter().map(|p| p.data().len() as u64).sum();

    change.unsupported = apply_diffs(tag, diffs);

    if opts.remove_cover {
        while !tag.pictures().is_empty() {
            let _ = tag.remove_picture(0);
        }
        change.cover = Some(CoverDiff {

View on GitHub (pinned to 8600b91f42)