{"record":{"id":"075d8b95c83f5ee8","repo":"jdx/mise","slug":"failed-to-decompress-archive","errorCode":null,"errorMessage":"failed to decompress #{archive}","messagePattern":"failed to decompress #(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/shim.rb","lineNumber":105,"sourceCode":"        raise \"#{context}: sha256 mismatch (expected #{sha256}, got #{actual})\"\n      end\n      tmp.rename(dest)\n    end\n    dest\n  end\n\n  # unpack an archive the way brew stages sources: if the archive contains a\n  # single top-level directory, its contents become the stage root\n  def unpack(archive, dest)\n    dest.mkpath\n    case archive.basename.to_s\n    when /\\.(tar\\.(gz|xz|bz2|zst)|tgz|txz|tbz2?|tar|crate)\\z/i\n      system_or_die \"tar\", \"xf\", archive.to_s, \"-C\", dest.to_s\n    when /\\.zip\\z/i\n      system_or_die \"unzip\", \"-qo\", archive.to_s, \"-d\", dest.to_s\n    when /\\.(gz|xz|bz2)\\z/i\n      data = `#{archive.to_s =~ /xz\\z/ ? \"xz -dc\" : archive.to_s =~ /bz2\\z/ ? \"bzip2 -dc\" : \"gzip -dc\"} #{Shellwords.escape(archive.to_s)}`\n      raise \"failed to decompress #{archive}\" unless $?.success?\n      (dest + archive.basename.to_s.sub(/\\.(gz|xz|bz2)\\z/i, \"\")).binwrite(data)\n    else\n      FileUtils.cp archive, dest\n    end\n    entries = dest.children\n    return entries.first if entries.size == 1 && entries.first.directory?\n    dest\n  end\n\n  def system_or_die(*args)\n    raise \"command failed: #{args.join(\" \")}\" unless system(*args)\n  end\nend\n\nmodule OS\n  def self.mac? = RbConfig::CONFIG[\"host_os\"].include?(\"darwin\")\n  def self.linux? = RbConfig::CONFIG[\"host_os\"].include?(\"linux\")\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/brew/shim.rb#L87-L123","documentation":"In the brew shim's unpack, single-file compressed archives (.gz/.xz/.bz2) are decompressed by piping through gzip/xz/bzip2 in a shell backtick. The failure check `$?.success?` failing raises this error, meaning the decompressor exited non-zero (corrupt archive, missing tool, or shell interpolation issue).","triggerScenarios":"unpack called on a .gz/.xz/.bz2 file whose stream is corrupt or truncated, or on a system where xz/bzip2/gzip is not installed, or when the archive filename contains characters the shell interpolation mishandles.","commonSituations":"Partially downloaded .tar.gz misclassified as .gz; minimal container images lacking xz; checksum-verified but corrupt-at-source archives.","solutions":["Ensure the required decompressor is installed (apt-get install xz-utils / bzip2) and on PATH.","Verify the archive is valid: gzip -t / xz -t <archive>; re-download if corrupt.","Confirm the file is actually a single-file compressed stream, not a tarball (use `file archive`); the extension must match the content.","If the archive is fine but still failing, check disk space in the destination."],"exampleFix":"// before (minimal image without xz)\n# no xz installed\n// after\nRUN apt-get update && apt-get install -y xz-utils","handlingStrategy":"validation","validationCode":"# ensure decompressors exist before unpack\n%w[gzip xz bzip2 tar].each do |t|\n  raise \"missing tool: #{t}\" unless system(\"command -v #{t}\", out: File::NULL)\nend","typeGuard":null,"tryCatchPattern":"begin\n  MiseDownload.unpack(archive, dest)\nrescue RuntimeError => e\n  raise unless e.message.start_with?(\"failed to decompress\")\n  # install xz/bzip2 or re-fetch a valid archive\nend","preventionTips":["Install gzip, xz-utils, and bzip2 in base images used for mise package installs.","Validate archives with gzip -t / xz -t after download.","Match archive extensions to actual content types."],"tags":["ruby","archive","decompression","brew"],"backgroundTag":"command-not-found","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}