use crate::cursor::OutOfBounds;
use std::convert::From;
use std::fmt;
#[derive(Debug)]
pub enum Error {
InvalidHeader,
InvalidRecord,
UnsupportedVersion,
OutOfBounds,
UnexpectedChunkSectionRecord(&'static str),
UnexpectedIndexSectionRecord(&'static str),
UnexpectedMessageRecord(&'static str),
Bzip2DecompressionError(String),
Lz4DecompressionError(String),
}
impl From<OutOfBounds> for Error {
fn from(_: OutOfBounds) -> Error {
Error::OutOfBounds
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use Error::*;
let s = match self {
InvalidHeader => "invalid header".to_string(),
InvalidRecord => "invalid record".to_string(),
UnsupportedVersion => "unsupported version".to_string(),
OutOfBounds => "out of bounds".to_string(),
UnexpectedChunkSectionRecord(t) => format!("unexpected {} in the chunk section", t),
UnexpectedIndexSectionRecord(t) => format!("unexpected {} in the index section", t),
UnexpectedMessageRecord(t) => format!("unexpected {} in chunk payload", t),
Bzip2DecompressionError(e) => format!("bzip2 decompression error: {}", e),
Lz4DecompressionError(e) => format!("LZ4 decompression error: {}", e),
};
write!(f, "rosbag::Error: {}", s)
}
}
impl std::error::Error for Error {}