use std::path::PathBuf;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("validation failed: {0}")]
Validation(#[from] ValidationError),
#[error("i/o error at {path}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("limit exceeded ({kind:?}): observed {observed} > limit {limit}")]
Limit {
kind: crate::diagnostic::LimitKind,
observed: u64,
limit: u64,
},
#[error(transparent)]
Provider(#[from] crate::provider::ProviderError),
#[error(transparent)]
Export(#[from] crate::exporter::ExportError),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ValidationError {
#[error("`{field}` must not be empty")]
Empty {
field: &'static str,
},
#[error("required field `{0}` not set")]
MissingField(&'static str),
#[error("`{field}` exceeds maximum byte length ({observed} > {limit})")]
TooLong {
field: &'static str,
observed: usize,
limit: usize,
},
#[error(
"`{field}` contains disallowed character {:?} at byte {offset}",
char::from(*byte)
)]
BadChar {
field: &'static str,
byte: u8,
offset: usize,
},
#[error("`{field}` failed rule `{rule}`")]
Shape {
field: &'static str,
rule: &'static str,
},
#[error("`{field}` out of range [{min}, {max}]: got {got}")]
Range {
field: &'static str,
min: i64,
max: i64,
got: i64,
},
}