behaviortree-core 0.1.0

Core implementaion of behaviortree
Documentation
// Copyright © 2024 Stephan Kunz
//! `behaviortree` behavior errors

use thiserror::Error;

use crate::ConstString;

use super::BehaviorState;

/// Behavior errors.
#[derive(Error, Debug)]
pub enum Error {
	/// Item is already registered
	#[error("the item {name} is already registered")]
	AlreadyRegistered {
		/// Name of the item
		name: ConstString,
	},
	/// Error in structural composition of a behaviors children
	#[error("behavior composition error: {txt}")]
	Composition {
		/// The textual error message.
		txt: ConstString,
	},
	/// Pass through errors from `databoard`
	#[error("a 'blackboard' error occured: {0}")]
	Databoard(#[from] databoard::Error),
	/// Pass through errors from `dataport`
	#[error("a 'port' error occured: {0}")]
	Dataport(#[from] dataport::Error),
	/// Pass through errors from nanoserde
	#[error("a deserialization error occured: {0}")]
	Nanoserde(#[from] nanoserde::DeJsonErr),
	/// Attribute is not a pre or post condition
	#[error("the attribute '{value}' is no pre or post condition")]
	NoCondition {
		/// The attribute
		value: ConstString,
	},
	/// Value is not a boolean type
	#[error("value {value} is not a boolean type")]
	NotABool {
		/// The non boolean value
		value: ConstString,
	},
	/// Parsing error during type conversion
	#[error("could not parse value '{value}' in {src}")]
	ParseError {
		/// The non parseable value
		value: ConstString,
		/// The source of this value
		src: ConstString,
	},
	/// Pass through errors from `core::num`
	#[error("could not parse int value: {0}")]
	ParseInt(#[from] core::num::ParseIntError),
	/// Type mismatch between port definiton and found value
	#[error("could not parse value for port {port} into specified type {typ}")]
	ParsePortValue {
		/// The ports name
		port: ConstString,
		/// The wanted data type
		typ: ConstString,
	},
	/// Port has not been defined in behavior
	#[error("port {port} is not declared in behavior {behavior}")]
	PortNotDeclared {
		/// Name of the port
		port: ConstString,
		/// Affected behavior
		behavior: ConstString,
	},
	/// Pass through errors from tinyscript
	#[error("a scripting error occured: {0}")]
	Scripting(#[from] tinyscript::Error),
	/// An invalid [`BehaviorState`] is reached
	#[error("child node of  {behavior} returned state {state} when not allowed")]
	State {
		/// The affected behavior
		behavior: ConstString,
		/// The invalid state
		state: BehaviorState,
	},
	/// Unable to set the pre or post condition
	#[error("unable to set the pre or post condition {value})")]
	UnableToSetCondition {
		/// Te condition thatcannot be set
		value: ConstString,
	},
}