use std::path::PathBuf;
use crate::identify::Encoding;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("{what}")]
Unsupported {
what: String,
},
#[error("{path}: not a container vtome reads ({found})")]
UnknownContainer {
path: PathBuf,
found: String,
},
#[error("no decoder for {encoding}: {remedy}")]
NoDecoder {
encoding: Encoding,
remedy: String,
},
#[error("{path}: {reason}")]
Demux {
path: PathBuf,
reason: String,
},
#[error("decoding {encoding}: {reason}")]
Decode {
encoding: Encoding,
reason: String,
},
#[error("encoding: {reason}")]
Encode {
reason: String,
},
#[error("{reason}")]
BadFrame {
reason: String,
},
#[error("no monitor matches {selector} ({available} attached)")]
NoSuchMonitor {
selector: String,
available: usize,
},
#[error("{reason}")]
Placement {
reason: String,
},
#[error("render: {reason}")]
Render {
reason: String,
},
#[error("{path}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
}
impl Error {
pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
Error::Io {
path: path.into(),
source,
}
}
pub(crate) fn unsupported(what: impl Into<String>) -> Self {
Error::Unsupported { what: what.into() }
}
#[cfg_attr(not(feature = "demux"), allow(dead_code))]
pub(crate) fn demux(path: impl Into<PathBuf>, reason: impl Into<String>) -> Self {
Error::Demux {
path: path.into(),
reason: reason.into(),
}
}
pub(crate) fn placement(reason: impl Into<String>) -> Self {
Error::Placement {
reason: reason.into(),
}
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;