#[derive(Debug)]
pub enum Error {
EOF,
FrameTooBig { input: usize },
FrameTooLong { input: u64 },
Read { source: std::io::Error },
Write { source: std::io::Error },
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::EOF => write!(f, "eof"),
Self::FrameTooBig { input } => write!(
f,
"failed to create ttyrec frame: got {} bytes of data, but \
ttyrec frames can be at most {} bytes",
input,
u32::max_value()
),
Self::FrameTooLong { input } => write!(
f,
"failed to create ttyrec frame: got {} seconds, but ttyrecs \
can be at most {} seconds",
input,
u32::max_value()
),
Self::Read { source } => {
write!(f, "failed to read from input: {source}")
}
Self::Write { source } => {
write!(f, "failed to write to output: {source}")
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Read { source } | Self::Write { source } => Some(source),
_ => None,
}
}
}
pub type Result<T> = std::result::Result<T, Error>;