use thiserror::Error;
use maps_io_ros::impl_error_constructors;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("{message}")]
App { message: String },
#[error(transparent)]
Core(#[from] maps_io_ros::Error),
#[error("[TOML error] {context} ({source})")]
TomlDeserialize {
context: String,
#[source]
source: toml::de::Error,
},
#[error("[TOML error] {context} ({source})")]
TomlSerialize {
context: String,
#[source]
source: toml::ser::Error,
},
}
impl Error {
#[allow(clippy::needless_pass_by_value)]
pub fn app(message: impl ToString) -> Self {
Self::App {
message: message.to_string(),
}
}
impl_error_constructors! {
toml_deserialize => TomlDeserialize, toml::de::Error;
toml_serialize => TomlSerialize, toml::ser::Error;
}
pub fn io(context: impl ToString, source: std::io::Error) -> Self {
Error::Core(maps_io_ros::Error::io(context, source))
}
}