Reference

std/binary/error

std/binary/src/error.trb

ReadError: why a read of a ByteReader or a BitReader did not answer a value.

type ReadError

type ReadError with Show, Error

Why a read failed, and the byte where it happened. Every case names an offset: counted from the start of the bytes the outermost reader was made from, so a limited reader names the same byte its parent would, and a log line can be checked against a hex dump by hand.

A format converts it into its own error through From, so that ? works in a function that answers that error:

extend ImageError with From<ReadError> {
  static fn from(value: ReadError): ImageError {
    ImageError.Broken(value.show())
  }
}

case Truncated

case Truncated(offset: Int, expected: String, needed: Int, available: Int)

needed bytes for expected at offset, and only available were left.

case TruncatedBits

case TruncatedBits(offset: Int, needed: Int, available: Int)

needed bits at offset of a BitReader, and only available were left.

case Unterminated

case Unterminated(offset: Int, available: Int)

A text that is to end in a NUL byte starts at offset, and none of the available bytes left is one.

case Overlong

case Overlong(offset: Int, expected: String)

A variable-length integer at offset is still going after the most bytes expected can have.

case Overflow

case Overflow(offset: Int, expected: String)

A variable-length integer at offset holds a value that expected cannot hold.

case InvalidText

case InvalidText(offset: Int)

Text that is not UTF-8: offset is the first byte that breaks it.

case OutOfRange

case OutOfRange(offset: Int, position: Int, length: Int)

A position that is not inside a reader of length bytes was asked for while it stood at offset.

fn offset

fn offset(): Int

The byte the failure names, counted from the start of the outermost reader's bytes.

fn show

fn show(): String

One line: what was expected, where, and what was there instead.