1use alloc::boxed::Box;
5
6pub struct Error {
8 module: &'static str,
10 source: Box<dyn core::error::Error>,
12}
13
14impl core::error::Error for Error {
16 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
17 Some(self.source.as_ref())
18 }
19}
20
21impl core::fmt::Debug for Error {
22 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23 write!(f, "Behaviortree(module: {}, error: {}", self.module, self.source)
24 }
25}
26
27impl core::fmt::Display for Error {
28 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
29 write!(f, "Behaviortree module '{}' failed with: {}", self.module, self.source)
30 }
31}
32
33impl From<behaviortree_core::error::Error> for Error {
34 fn from(source: behaviortree_core::error::Error) -> Self {
35 Self {
36 module: "core",
37 source: Box::new(source),
38 }
39 }
40}
41
42impl From<behaviortree_core::tree::error::Error> for Error {
43 fn from(source: behaviortree_core::tree::error::Error) -> Self {
44 Self {
45 module: "core::tree",
46 source: Box::new(source),
47 }
48 }
49}
50
51impl From<behaviortree_factory::error::Error> for Error {
52 fn from(source: behaviortree_factory::error::Error) -> Self {
53 Self {
54 module: "factory",
55 source: Box::new(source),
56 }
57 }
58}
59impl From<databoard::Error> for Error {
60 fn from(source: databoard::Error) -> Self {
61 Self {
62 module: "databoard",
63 source: Box::new(source),
64 }
65 }
66}
67
68impl From<dataport::Error> for Error {
69 fn from(source: dataport::Error) -> Self {
70 Self {
71 module: "dataport",
72 source: Box::new(source),
73 }
74 }
75}
76
77impl From<woxml::Error> for Error {
78 fn from(source: woxml::Error) -> Self {
79 Self {
80 module: "woxml",
81 source: Box::new(source),
82 }
83 }
84}
85
86#[cfg(feature = "std")]
87impl From<std::io::Error> for Error {
88 fn from(source: std::io::Error) -> Self {
89 Self {
90 module: "std::io",
91 source: Box::new(source),
92 }
93 }
94}