noxu_bind/error.rs
1//! Error types for the noxu-bind crate.
2//!
3
4use thiserror::Error;
5
6/// Errors that can occur during binding operations.
7#[derive(Debug, Error)]
8pub enum BindError {
9 /// Buffer underflow: attempted to read more bytes than available.
10 #[error("buffer underflow: needed {needed} bytes, got {available}")]
11 BufferUnderflow {
12 /// Number of bytes needed.
13 needed: usize,
14 /// Number of bytes available.
15 available: usize,
16 },
17
18 /// Invalid data encountered during deserialization.
19 #[error("invalid data: {0}")]
20 InvalidData(String),
21
22 /// String encoding/decoding error.
23 #[error("string encoding error: {0}")]
24 StringEncoding(String),
25
26 /// Unsupported type encountered.
27 #[error("unsupported type: {0}")]
28 UnsupportedType(String),
29
30 /// The on-disk payload was written by an older or newer version of
31 /// the binding's wire format than this build understands.
32 ///
33 /// Returned by `SerdeBinding::entry_to_object` when the 2-byte
34 /// header (`[magic, version]`) does not match this build's
35 /// expectation. See `docs/src/getting-started/bindings.md` for
36 /// the format description and migration guidance.
37 #[error(
38 "binding version mismatch: header {{ magic: 0x{found_magic:02X}, \
39 version: 0x{found_version:02X} }} but this build expects \
40 {{ magic: 0x{expected_magic:02X}, version: 0x{expected_version:02X} }}"
41 )]
42 VersionMismatch {
43 /// Expected magic byte.
44 expected_magic: u8,
45 /// Expected version byte.
46 expected_version: u8,
47 /// Magic byte found in the payload (or 0 if the payload was
48 /// too short to contain one).
49 found_magic: u8,
50 /// Version byte found in the payload (or 0 if the payload was
51 /// too short to contain one).
52 found_version: u8,
53 },
54}
55
56/// A specialized Result type for binding operations.
57pub type Result<T> = std::result::Result<T, BindError>;