1pub type Result<T> = core::result::Result<T, Error>;
5
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8pub enum Error {
9 #[error(
12 "cannot store {strings} strings: id type '{id_type}' is too small; use a larger StringId type"
13 )]
14 TooManyStrings {
15 strings: usize,
17 id_type: &'static str,
19 },
20 #[error(
23 "cannot store {bytes} bytes of string data: offset type '{offset_type}' is too small; use a larger offset type"
24 )]
25 TooManyBytesForOffsetType {
26 bytes: usize,
28 offset_type: &'static str,
30 },
31}
32
33#[cfg(any(debug_assertions, test))]
34pub(crate) type ValidationResult<T> = core::result::Result<T, ValidationError>;
35
36#[cfg(any(debug_assertions, test))]
37#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
38pub(crate) enum ValidationError {
39 #[error("invalid string table: {strings} strings do not fit in id type '{id_type}'")]
40 TooManyStrings {
41 strings: usize,
42 id_type: &'static str,
43 },
44 #[error("invalid string table: {bytes} bytes do not fit in offset type '{offset_type}'")]
45 TooManyBytesForOffsetType {
46 bytes: usize,
47 offset_type: &'static str,
48 },
49 #[error("invalid string table: offsets must end with a sentinel equal to total byte length")]
50 MissingSentinelOffset,
51 #[error("invalid string table: final offset is {found}, but byte length is {expected}")]
52 LastOffsetMismatch { found: usize, expected: usize },
53 #[error("invalid string table: offset[{index}] = {offset} is out of bounds (byte length {bytes_len})")]
54 OffsetOutOfBounds {
55 index: usize,
56 offset: usize,
57 bytes_len: usize,
58 },
59 #[error(
60 "invalid string table: offsets must be non-decreasing; offset[{index}] = {current}, previous = {previous}"
61 )]
62 OffsetsNotMonotonic {
63 index: usize,
64 previous: usize,
65 current: usize,
66 },
67 #[error("invalid string table: bytes for string index {index} are not valid UTF-8")]
68 InvalidUtf8 { index: usize },
69 #[error("invalid string table: string index {index} in null-padded mode has no trailing byte")]
70 NullPaddedStringMissingTerminatorByte { index: usize },
71 #[error(
72 "invalid string table: string index {index} in null-padded mode must end with a NUL byte"
73 )]
74 NullPaddedStringMissingTrailingNul { index: usize },
75}