lance-format/lance

Add `ReadFileError` and `DecodeColumnError` wrappers to provide better context for decoding errors

Open

#5.602 geöffnet am 31. Dez. 2025

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)Rust (695 Forks)github user discovery
good first issue

Repository-Metriken

Stars
 (6.582 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 1h) (219 gemergte PRs in 30 T)

Beschreibung

Currently, errors that happen when decoding a column are missing information about:

  1. What column that is
  2. What file we are reading

This context is available higher up in the call stack that the main error is generate. We can add additional context by adding wrapper errors.

This approach is described nicely in https://sabrinajewson.org/blog/errors.

Basically, want to do things like:

enum DecodeError {
    NumberOutOfRange,
    ...
}

struct DecodeFieldError {
    field_name: String,
    field_id: i32,
    offset: u64,
    source: DecodeError,
}

fn decode(field: Field, data: Bytes) -> Result<_, DecodeFieldError> {
    ...
}

enum ReadFileErrorKind {
    IO(ObjectStoreError),
    Decode(DecodeFieldError),
}

struct ReadFileError {
    path: Path,
    kind: ReadFileErrorKind,
}

fn read_file(path: Path) -> Result<_, ReadFileError> {
    let data = read_data(path)?;
    for field in data.schema() {
        decode(field, data).map_err(|err: DecodeFieldError| {
            ReadFileError { path, kind: ReadFileErrorKind::Decode(err) }
        });
    }
}

And then the error stack would look like:

Error: failed to read file 'data.lance'

Caused by:
    0: failed to read field 'age' (id: 10) for row offset 10
    1: number out of range

Contributor Guide