ruby/rubygems · error · Gem::SafeMarshal::Reader::UnconsumedBytesError

expected EOF, got #{@io.read(10).inspect}... after top-level

Error message

expected EOF, got #{@io.read(10).inspect}... after top-level element #{root.class}

What it means

Error "expected EOF, got #{@io.read(10).inspect}... after top-level element #{root.class}" thrown in ruby/rubygems.

Source

Thrown at lib/rubygems/safe_marshal/reader.rb:41

      class DataTooShortError < Error
      end

      class NegativeLengthError < Error
      end

      class LengthTooLongError < Error
      end

      def initialize(io)
        @io = io
        @object_links = {}
        @symbol_links = {}
      end

      def read!
        read_header
        root = read_element
        raise UnconsumedBytesError, "expected EOF, got #{@io.read(10).inspect}... after top-level element #{root.class}" unless @io.eof?
        root
      end

      private

      MARSHAL_VERSION = [Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION].map(&:chr).join.freeze
      private_constant :MARSHAL_VERSION

      def read_header
        v = @io.read(2)
        raise UnsupportedVersionError, "Unsupported marshal version #{v.bytes.map(&:ord).join(".")}, expected #{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}" unless v == MARSHAL_VERSION
      end

      def read_bytes(n)
        raise NegativeLengthError if n < 0
        str = @io.read(n)
        raise EOFError, "expected #{n} bytes, got EOF" if str.nil?
        raise DataTooShortError, "expected #{n} bytes, got #{str.inspect}" unless str.bytesize == n

View on GitHub (pinned to 86cbb817a3)

Solutions

  1. The marshal stream has trailing garbage; re-download the gem/metadata
  2. Rebuild the gem if you generated its metadata

When it happens

Trigger: Thrown at lib/rubygems/safe_marshal/reader.rb:41 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/57d40b76a437c110. Report an issue: GitHub.