{"record":{"id":"d638d61b42a3d104","repo":"jdx/mise","slug":"untar-only-supports-tar-formats-got","errorCode":null,"errorMessage":"untar only supports tar formats, got {}","messagePattern":"untar only supports tar formats, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/file.rs","lineNumber":2139,"sourceCode":"        | ExtractionFormat::Bz2\n        | ExtractionFormat::Zst\n        | ExtractionFormat::Br\n        | ExtractionFormat::Lz4\n        | ExtractionFormat::Sz => {\n            bail!(\"extract_archive does not support compressed single-file format: {format}\")\n        }\n        ExtractionFormat::Rar => bail!(\"rar format not supported\"),\n    }\n}\n\npub(crate) fn untar(\n    archive: &Path,\n    dest: &Path,\n    format: ExtractionFormat,\n    opts: &ExtractOptions,\n) -> Result<()> {\n    if !format.is_tar_archive() && format != ExtractionFormat::Raw {\n        bail!(\"untar only supports tar formats, got {}\", format);\n    }\n\n    debug!(\"tar -xf {} -C {}\", archive.display(), dest.display());\n    if let Some(pr) = &opts.pr {\n        pr.set_message(format!(\n            \"extract {}\",\n            archive.file_name().unwrap().to_string_lossy()\n        ));\n    }\n\n    let err = || {\n        let archive = display_path(archive);\n        let dest = display_path(dest);\n        format!(\"failed to extract tar: {archive} to {dest}\")\n    };\n\n    run_blocking(|| {\n        let tar = open_tar(format, archive)?;","sourceCodeStart":2121,"sourceCodeEnd":2157,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/file.rs#L2121-L2157","documentation":"untar asserts upfront that the given ExtractionFormat is a tar archive (or Raw, for legacy behavior) with \"untar only supports tar formats, got {format}\". It is an internal precondition: callers must route non-tar formats to unzip/un7z/decompress_file instead.","triggerScenarios":"Calling untar directly (or via a code path that does) with Zip, SevenZip, Rar, Gz, Xz, Bz2, Zst, Br, Lz4, or Sz formats.","commonSituations":"Custom backend code dispatches every download to untar; format detection misclassifies a zip as extractable via tar; refactoring moved dispatch logic and dropped the extract_archive indirection.","solutions":["Call extract_archive instead of untar so zip/7z/single-file formats dispatch correctly","Guard the call with format.is_tar_archive() || format == Raw before invoking untar","Fix format detection so zip archives are classified as Zip and routed to unzip","For raw compressed files, use decompress_file rather than untar"],"exampleFix":"// before\nuntar(&archive, &dest, ExtractionFormat::Zip, &opts)?;\n// after\nextract_archive(&archive, &dest, ExtractionFormat::Zip, &opts)?;","handlingStrategy":"validation","validationCode":"if !(fmt.is_tar_archive() || fmt == ExtractionFormat::Raw) {\n    return Err(anyhow!(\"untar requires tar format, got {fmt}\"));\n}\nuntar(&archive, &dest, fmt, &opts)?;","typeGuard":"fn is_untarable(f: ExtractionFormat) -> bool {\n    f.is_tar_archive() || f == ExtractionFormat::Raw\n}","tryCatchPattern":"match untar(&archive, &dest, fmt, &opts) {\n    Err(e) if e.to_string().contains(\"untar only supports tar formats\") => {\n        extract_archive(&archive, &dest, fmt, &opts)?; // correct dispatch\n    }\n    other => other?,\n}","preventionTips":["Always dispatch archives through extract_archive, not untar directly","Assert is_tar_archive() at call sites that need untar specifically","Keep zip/7z/rar out of tar paths by testing format detection","Remember Raw is allowed and treated as gzip-compressed tar (legacy behavior)"],"tags":["archive","tar","invalid-argument","internal-guard"],"backgroundTag":"invalid-argument-value","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}