use alloc::boxed::Box;
pub struct Error {
module: &'static str,
source: Box<dyn core::error::Error>,
}
impl core::error::Error for Error {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
Some(self.source.as_ref())
}
}
impl core::fmt::Debug for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Behaviortree(module: {}, error: {}", self.module, self.source)
}
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Behaviortree module '{}' failed with: {}", self.module, self.source)
}
}
impl From<behaviortree_core::error::Error> for Error {
fn from(source: behaviortree_core::error::Error) -> Self {
Self {
module: "core",
source: Box::new(source),
}
}
}
impl From<behaviortree_core::tree::error::Error> for Error {
fn from(source: behaviortree_core::tree::error::Error) -> Self {
Self {
module: "core::tree",
source: Box::new(source),
}
}
}
impl From<behaviortree_factory::error::Error> for Error {
fn from(source: behaviortree_factory::error::Error) -> Self {
Self {
module: "factory",
source: Box::new(source),
}
}
}
impl From<databoard::Error> for Error {
fn from(source: databoard::Error) -> Self {
Self {
module: "databoard",
source: Box::new(source),
}
}
}
impl From<dataport::Error> for Error {
fn from(source: dataport::Error) -> Self {
Self {
module: "dataport",
source: Box::new(source),
}
}
}
impl From<woxml::Error> for Error {
fn from(source: woxml::Error) -> Self {
Self {
module: "woxml",
source: Box::new(source),
}
}
}
#[cfg(feature = "std")]
impl From<std::io::Error> for Error {
fn from(source: std::io::Error) -> Self {
Self {
module: "std::io",
source: Box::new(source),
}
}
}