End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Encoding::InvalidByteSequenceError#error_bytes
ecerr.error_bytes → string
transcode.c
View on GitHub ↗
static VALUE
ecerr_error_bytes(VALUE self)
{
return rb_attr_get(self, rb_intern("error_bytes"));
}
Returns the discarded bytes when Encoding::InvalidByteSequenceError occurs.
Example
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") begin ec.convert("abc\xA1\xFFdef") rescue Encoding::InvalidByteSequenceError p $! #=> #<Encoding::InvalidByteSequenceError: "\xA1" followed by "\xFF" on EUC-JP> puts $!.error_bytes.dump #=> "\xA1" puts $!.readagain_bytes.dump #=> "\xFF" end
See also
#destination_encoding_name
#incomplete_input?
#destination_encoding
#readagain_bytes
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1