ruby/rubygems · error · Gem::Exception

Invalid spec cache file in #{local_file}

Error message

Invalid spec cache file in #{local_file}

What it means

Error "Invalid spec cache file in #{local_file}" thrown in ruby/rubygems.

Source

Thrown at lib/rubygems/source.rb:279

    retried    = false

    if update_cache?
      require "fileutils"
      FileUtils.mkdir_p cache_dir
    end

    spec_dump = fetcher.cache_update_path spec_path, local_file, update_cache?

    Gem.load_safe_marshal
    begin
      Gem::NameTuple.from_list Gem::SafeMarshal.safe_load(spec_dump)
    rescue ArgumentError
      if update_cache? && !retried
        FileUtils.rm local_file
        retried = true
        retry
      else
        raise Gem::Exception.new("Invalid spec cache file in #{local_file}")
      end
    end
  end

  ##
  # Builds the name tuple list for +type+ from the compact index versions
  # file. Returns nil when the source does not provide a usable compact
  # index, so the caller can fall back to the Marshal spec indexes.

  def load_compact_index_specs(type)
    return unless %w[http https].include?(uri.scheme)

    versions = compact_index_versions
    return if versions.nil? || versions.empty?

    tuples = []

    versions.each_value do |rows|

View on GitHub (pinned to 86cbb817a3)

Solutions

  1. Delete the corrupt spec cache file shown in the message; RubyGems will refetch it

When it happens

Trigger: Thrown at lib/rubygems/source.rb:279 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ruby/rubygems@86cbb817a3 (2026-08-23). Data as JSON: /api/errors/cb0490493df53376. Report an issue: GitHub.