Error Handling

Decoders return a typed error result. They do not panic on malformed input. This page documents the shape of error handling you should expect.

Broad error categories

Decode errors fall into a few broad categories:

  • Not our format — the input bytes aren’t what the decoder was built to read. Handle by trying a different decoder or failing.
  • Corrupted input — header or payload failed to parse. Treat as data corruption; quarantine and alert.
  • Unsupported version — file was produced by a newer encoder than your decoder knows about. Update the decoder.

Exact error type names and discriminants are defined in the C header or Rust crate bundled with the decoder download.

Pattern: fallback on unknown formats

let raster = match ript::decode(&bytes) {
    Ok(r) => r,
    Err(e) if e.is_not_our_format() => {
        try_other_decoders(&bytes)?
    }
    Err(e) => return Err(e.into()),
};

Pattern: quarantine corrupt inputs

Don’t silently skip decode failures. Something produced the bad file; you want to know.

match ript::decode(&bytes) {
    Ok(r) => process(r),
    Err(e) if e.is_corruption() => {
        move_to_quarantine(&path);
        alert_oncall(&path);
    }
    Err(e) => return Err(e.into()),
}

Versioning

Decoders handle every wire-format version up to the one they were built against. Older decoders on newer files return an unsupported-version error. Keep decoders current.