use std::io;
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("I/O error: {0}")]
Io(#[from] io::Error),
#[error("invalid wfdisc line length: got {got} chars, expected 283 (CSS 3.0) or 287 (NNSA KB Core)")]
InvalidLineLength {
got: usize,
},
#[error("failed to parse field `{field}` (value `{value}`): {source}")]
ParseField {
field: &'static str,
value: String,
#[source]
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},
#[error("unknown datatype code `{code}` (expected one of s4, s2, s3, i4, i2, t4, t8, f4, f8, a0, a#, b0, b#, c0, c#, e1, g2, cd, sc)")]
UnknownDatatype {
code: String,
},
#[error("datatype `{0}` is recognised but sample decoding is not yet supported")]
UnsupportedDatatype(crate::DataType),
#[error("waveform file {path:?} truncated: needed {needed} bytes at offset {offset}, got {got}")]
TruncatedWaveform {
path: PathBuf,
offset: u64,
needed: usize,
got: usize,
},
#[error("waveform file not found: tried {tried:?}")]
WaveformNotFound {
tried: Vec<PathBuf>,
},
#[error("sample payload size {requested} bytes exceeds limit of {max} bytes")]
SampleSizeExceeded {
requested: usize,
max: usize,
},
#[error("invalid value for field `{field}`: {reason}")]
InvalidFieldValue {
field: &'static str,
reason: &'static str,
},
#[error("invalid UTF-8 in field `{field}` at column bytes {start}..{end}")]
InvalidUtf8 {
field: &'static str,
start: usize,
end: usize,
},
#[error(
"line length {got} does not match locked schema {schema:?} (expected {expected})"
)]
MixedSchemaInLockedMode {
got: usize,
schema: crate::Schema,
expected: usize,
},
#[error("path escapes sandbox base {base:?}: {reason}")]
PathTraversal {
base: PathBuf,
reason: &'static str,
},
}