use thiserror::Error;
use crate::{FormatCode, WavType};
pub type WaversResult<T> = Result<T, WaversError>;
#[derive(Error, Debug)]
pub enum WaversError {
#[error("Format error: {0}")]
Format(#[from] FormatError),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("UTF-8 conversion error: {0}")]
Utf8Error(#[from] std::str::Utf8Error),
#[error("Invalid seek operation: current position {current}, max data position {max}, attempted to read {attempted} bytes")]
InvalidSeekOperation {
current: u64,
max: u64,
attempted: u64,
},
#[cfg(feature = "ndarray")]
#[error("NdArray error: {0}")]
NdArrayError(#[from] ndarray::ShapeError),
}
#[derive(Error, Debug)]
pub enum FormatError {
#[error(
"Invalid type: main format code {main}, bits per sample {bits}, sub-format code {sub}"
)]
InvalidType {
main: FormatCode,
bits: u16,
sub: FormatCode,
},
#[error("Invalid FMT chunk size: {0}")]
InvalidFmtChunkSize(usize),
#[error("Invalid number of bits per sample: {0}")]
InvalidBitsPerSample(u16),
#[error("Invalid type ID '{0}'")]
InvalidTypeId(&'static str),
#[error("Invalid WAV type specified: {0}")]
InvalidWavType(WavType),
#[error("Unsupported write format: main format {main}, sub-format {sub}")]
UnsupportedWriteFormat { main: FormatCode, sub: FormatCode },
}