ruby/rubygems · error · Gem::SafeMarshal::Reader::DataTooShortError
expected #{n} bytes, got #{str.inspect}
Error message
expected #{n} bytes, got #{str.inspect} What it means
Error "expected #{n} bytes, got #{str.inspect}" thrown in ruby/rubygems.
Source
Thrown at lib/rubygems/safe_marshal/reader.rb:59
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
str
end
def read_byte
@io.getbyte || raise(EOFError, "Unexpected EOF")
end
def read_integer
b = read_byte
case b
when 0x00
0
when 0x01
read_byte
when 0x02
read_byte | (read_byte << 8)
when 0x03View on GitHub (pinned to 86cbb817a3)
Solutions
- The marshal data is corrupt; re-download the gem or metadata file
When it happens
Trigger: Thrown at lib/rubygems/safe_marshal/reader.rb:59 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/b622ecf45dd90347.
Report an issue: GitHub.