#[doc(hidden)]
extern crate alloc;
use super::BehaviorState;
use crate::ConstString;
#[non_exhaustive]
pub enum Error {
Composition {
txt: ConstString,
},
Databoard {
source: databoard::Error,
},
Nanoserde {
source: nanoserde::DeJsonErr,
},
NoCondition {
value: ConstString,
},
NotABool {
value: ConstString,
},
ParseError {
value: ConstString,
src: ConstString,
},
ParseInt {
source: core::num::ParseIntError,
},
ParsePortValue {
port: ConstString,
typ: ConstString,
},
Port {
source: crate::port::error::Error,
},
PortNotDeclared {
port: ConstString,
behavior: ConstString,
},
Scripting {
source: tinyscript::Error,
},
State {
behavior: ConstString,
state: BehaviorState,
},
UnableToSetCondition {
value: ConstString,
},
}
impl core::error::Error for Error {
}
impl core::fmt::Debug for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Composition { txt } => write!(f, "Composition({txt})"),
Self::Databoard { source } => write!(f, "Databoard({source})"),
Self::Nanoserde { source } => write!(f, "Nanoserde({source})"),
Self::NoCondition { value } => write!(f, "NoCondition(value: {value})"),
Self::NotABool { value } => write!(f, "NotABool(value: {value})"),
Self::ParseError { value, src } => write!(f, "ParseError(value: {value}, src: {src})"),
Self::ParseInt { source } => write!(f, "ParseInt({source})"),
Self::ParsePortValue { port, typ } => write!(f, "ParsePort(port: {port}, type: {typ})"),
Self::Port { source } => write!(f, "Port({source})"),
Self::PortNotDeclared { port, behavior } => write!(f, "PortNotDeclared(port: {port}, behavior: {behavior})"),
Self::Scripting { source } => write!(f, "Scripting({source})"),
Self::State { behavior, state } => write!(f, "State(behavior: {behavior}, state: {state})"),
Self::UnableToSetCondition { value } => write!(f, "UnableToSetCondition(value: {value})"),
}
}
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Composition { txt } => write!(f, "behavior composition error: {txt}"),
Self::Databoard { source } => write!(f, "a blackboard error occured: {source}"),
Self::Nanoserde { source } => write!(f, "a deserialization error occured: {source}"),
Self::NoCondition { value } => write!(f, "the attribute '{value}' is no pre or post condition"),
Self::NotABool { value } => write!(f, "value {value} is not a boolean type"),
Self::ParseError { value, src } => write!(f, "could not parse value '{value}' in {src}"),
Self::ParseInt { source } => write!(f, "could not parse int value: {source}"),
Self::ParsePortValue { port, typ } => {
write!(f, "could not parse value for port {port} into specified type {typ}")
}
Self::Port { source } => write!(f, "a port error occured: {source}"),
Self::PortNotDeclared { port, behavior } => write!(f, "port {port} is not declared in behavior {behavior}"),
Self::Scripting { source } => write!(f, "a scripting error occured: {source}"),
Self::State { behavior, state } => {
write!(f, "child node of {behavior} returned state {state} when not allowed")
}
Self::UnableToSetCondition { value } => write!(f, "unable to set the pre or post condition {value})"),
}
}
}
impl From<crate::port::error::Error> for Error {
fn from(source: crate::port::error::Error) -> Self {
Self::Port { source }
}
}
impl From<core::num::ParseIntError> for Error {
fn from(source: core::num::ParseIntError) -> Self {
Self::ParseInt { source }
}
}
impl From<databoard::Error> for Error {
fn from(source: databoard::Error) -> Self {
Self::Databoard { source }
}
}
impl From<tinyscript::Error> for Error {
fn from(source: tinyscript::Error) -> Self {
Self::Scripting { source }
}
}
impl From<nanoserde::DeJsonErr> for Error {
fn from(source: nanoserde::DeJsonErr) -> Self {
Self::Nanoserde { source }
}
}