Skip to main content

behaviortree_core/
error.rs

1// Copyright © 2024 Stephan Kunz
2//! `behaviortree` behavior errors
3
4use thiserror::Error;
5
6use crate::ConstString;
7
8use super::BehaviorState;
9
10/// Behavior errors.
11#[derive(Error, Debug)]
12pub enum Error {
13	/// Item is already registered
14	#[error("the item {name} is already registered")]
15	AlreadyRegistered {
16		/// Name of the item
17		name: ConstString,
18	},
19	/// Error in structural composition of a behaviors children
20	#[error("behavior composition error: {txt}")]
21	Composition {
22		/// The textual error message.
23		txt: ConstString,
24	},
25	/// Pass through errors from `databoard`
26	#[error("a 'blackboard' error occured: {0}")]
27	Databoard(#[from] databoard::Error),
28	/// Pass through errors from `dataport`
29	#[error("a 'port' error occured: {0}")]
30	Dataport(#[from] dataport::Error),
31	/// Pass through errors from nanoserde
32	#[error("a deserialization error occured: {0}")]
33	Nanoserde(#[from] nanoserde::DeJsonErr),
34	/// Attribute is not a pre or post condition
35	#[error("the attribute '{value}' is no pre or post condition")]
36	NoCondition {
37		/// The attribute
38		value: ConstString,
39	},
40	/// Value is not a boolean type
41	#[error("value {value} is not a boolean type")]
42	NotABool {
43		/// The non boolean value
44		value: ConstString,
45	},
46	/// Parsing error during type conversion
47	#[error("could not parse value '{value}' in {src}")]
48	ParseError {
49		/// The non parseable value
50		value: ConstString,
51		/// The source of this value
52		src: ConstString,
53	},
54	/// Pass through errors from `core::num`
55	#[error("could not parse int value: {0}")]
56	ParseInt(#[from] core::num::ParseIntError),
57	/// Type mismatch between port definiton and found value
58	#[error("could not parse value for port {port} into specified type {typ}")]
59	ParsePortValue {
60		/// The ports name
61		port: ConstString,
62		/// The wanted data type
63		typ: ConstString,
64	},
65	/// Port has not been defined in behavior
66	#[error("port {port} is not declared in behavior {behavior}")]
67	PortNotDeclared {
68		/// Name of the port
69		port: ConstString,
70		/// Affected behavior
71		behavior: ConstString,
72	},
73	/// Pass through errors from tinyscript
74	#[error("a scripting error occured: {0}")]
75	Scripting(#[from] tinyscript::Error),
76	/// An invalid [`BehaviorState`] is reached
77	#[error("child node of  {behavior} returned state {state} when not allowed")]
78	State {
79		/// The affected behavior
80		behavior: ConstString,
81		/// The invalid state
82		state: BehaviorState,
83	},
84	/// Unable to set the pre or post condition
85	#[error("unable to set the pre or post condition {value})")]
86	UnableToSetCondition {
87		/// Te condition thatcannot be set
88		value: ConstString,
89	},
90}