{"record":{"id":"528c26645252e237","repo":"tonhowtf/omniget","slug":"a-capa-cover-n-o-png-jpeg-gif-ou-bmp","errorCode":null,"errorMessage":"a capa {cover} não é PNG, JPEG, GIF ou BMP","messagePattern":"a capa (.+?) não é PNG, JPEG, GIF ou BMP","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/audio_tag.rs","lineNumber":1232,"sourceCode":"\nfn edit_one(path: &Path, diffs: &[FieldDiff], opts: &EditOptions) -> anyhow::Result<FileChange> {\n    let path_str = path.to_string_lossy().to_string();\n    let mut change = FileChange {\n        path: path_str.clone(),\n        file_name: file_name_of(&path_str),\n        diffs: diffs.to_vec(),\n        cover: None,\n        unsupported: Vec::new(),\n        written: false,\n        backup: None,\n        error: None,\n    };\n\n    let cover_bytes = if let Some(cover) = opts.cover_path.as_deref().filter(|s| !s.is_empty()) {\n        let data =\n            std::fs::read(cover).with_context(|| format!(\"não consegui ler a capa em {cover}\"))?;\n        let mime =\n            mime_of(&data).ok_or_else(|| anyhow!(\"a capa {cover} não é PNG, JPEG, GIF ou BMP\"))?;\n        Some((data, mime))\n    } else {\n        None\n    };\n\n    let mut tagged = lofty::read_from_path(path).map_err(|e| anyhow!(e.to_string()))?;\n    let tag_type = tagged.primary_tag_type();\n    if tagged.primary_tag_mut().is_none() {\n        tagged.insert_tag(Tag::new(tag_type));\n    }\n    let tag = tagged\n        .primary_tag_mut()\n        .ok_or_else(|| anyhow!(\"o formato não aceita a tag {tag_type:?}\"))?;\n\n    let before_cover = tag.pictures().len();\n    let before_bytes: u64 = tag.pictures().iter().map(|p| p.data().len() as u64).sum();\n\n    change.unsupported = apply_diffs(tag, diffs);","sourceCodeStart":1214,"sourceCodeEnd":1250,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/audio_tag.rs#L1214-L1250","documentation":"This error is thrown when a cover image supplied via opts.cover_path was read successfully but mime_of() could not detect PNG, JPEG, GIF or BMP magic bytes in the file's data. The library only supports embedding covers in those four formats, and refuses any other file type (or an unrecognized one) rather than passing a bogus MIME type to the lofty tag writer. The file path is interpolated into the message so the user knows which cover was rejected.","triggerScenarios":"Calling the audio tag editing function with opts.cover_path set to a file that is not a PNG/JPEG/GIF/BMP (e.g. WebP, TIFF, SVG, AVIF) or a file whose leading bytes mime_of() cannot recognize (corrupted image, text file renamed to .png).","commonSituations":"User picks a modern WebP/AVIF image downloaded from the web as album art; a placeholder or HTML error page saved as cover.jpg; an image so truncated that its magic bytes are missing.","solutions":["Convert the cover to PNG or JPEG before passing the path (e.g. with imagemagick: magick input.webp cover.png).","Verify the file is actually an image of an allowed type: run `file <cover>` or check the first bytes for PNG/JPEG/GIF/BMP signatures.","If the cover is optional, leave opts.cover_path empty/None so no cover is attached.","Extend mime_of() to support additional formats if WebP etc. are genuinely needed and lofty accepts them."],"exampleFix":"// before\nlet data = std::fs::read(\"cover.webp\")?; // mime_of -> None\nlet mime = mime_of(&data).ok_or_else(|| anyhow!(\"a capa {cover} não é PNG, JPEG, GIF ou BMP\"))?;\n// after\n// convert first: `magick cover.webp cover.png`, then\nlet data = std::fs::read(\"cover.png\")?;\nlet mime = mime_of(&data).ok_or_else(|| anyhow!(\"a capa {cover} não é PNG, JPEG, GIF ou BMP\"))?;","handlingStrategy":"validation","validationCode":"fn is_supported_cover(path: &str) -> anyhow::Result<bool> {\n    let data = std::fs::read(path)?;\n    Ok(mime_of(&data)\n        .map(|m| matches!(m, \"image/png\" | \"image/jpeg\" | \"image/gif\" | \"image/bmp\"))\n        .unwrap_or(false))\n}","typeGuard":"fn is_image_mime(mime: &str) -> bool {\n    matches!(mime, \"image/png\" | \"image/jpeg\" | \"image/gif\" | \"image/bmp\")\n}","tryCatchPattern":"match edit_tags_with_cover(path, cover) {\n    Ok(change) => /* aplicar */,\n    Err(e) if e.to_string().contains(\"não é PNG, JPEG, GIF ou BMP\") =>\n        eprintln!(\"capa em formato não suportado: converta para PNG/JPEG/GIF/BMP\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Always run the file through `file`/magic-byte sniffing before attaching a cover.","Prefer PNG or JPEG covers downloaded from album-art sources.","Convert WebP/AVIF downloads to PNG automatically at import time.","Leave cover_path empty when unsure instead of guessing the format."],"tags":["rust","audio-tagging","image-format","validation"],"backgroundTag":"unsupported-image-format","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}