behaviortree-core 0.1.0

Core implementaion of behaviortree
Documentation
// Copyright © 2025 Stephan Kunz
//! `XmlParser` errors.

use thiserror::Error;

use crate::ConstString;

/// `xml` error type
#[derive(Error, Debug)]
pub enum Error {
	/// Auroremap is only allowed for subtrees
	#[error("the attribute '_autoremap' is only allowed for subtrees not for '{tag}'")]
	Autoremap {
		/// tag
		tag: ConstString,
	},
	/// Value for auroremap is wrong
	#[error("the value for autoremap must be a boolean 'true' or 'false'")]
	AutoremapValue,
	/// `BtCPP format` is not supported
	#[error("the attribute 'BTCPP_format' must have the value '4'")]
	BtCppFormat,
	/// The behavior does not allow children
	#[error("the leaf behavior '{behavior}' may not have any children")]
	ChildrenNotAllowed {
		/// The affected behavior
		behavior: ConstString,
	},
	/// A wrong pre- or post-condition
	#[error("the pre-/post-condition key '{key}' is erronous: {source}")]
	Condition {
		/// The affected condition
		key: ConstString,
		/// original error
		source: crate::error::Error,
	},
	/// The ports value could not be initializd from a str value
	#[error("port '{port}' could not be initialized from str '{value}'")]
	ConversionFromStr { port: ConstString, value: ConstString },
	/// Pass through errors from databoard
	#[error("the databoard key '{key}' caused the error: {source}")]
	Databoard {
		/// The requested entry key
		key: ConstString,
		/// original error
		source: databoard::Error,
	},
	/// Pass through errors from dataport
	#[error("the port '{key}' caused the error: {source}")]
	Dataport {
		/// The requested entry key
		key: ConstString,
		/// original error
		source: dataport::Error,
	},
	// A behavior definition cannot be found
	#[error("the behavior definition for the id '{id}' could not be found")]
	DefinitionNotFound {
		/// Id of the wanted behavior
		id: ConstString,
	},
	/// Tag `BehaviorTree` is missing
	#[error("definition for '{tree}' does not contain a 'BehaviorTree' tag")]
	MissingBehaviorTree {
		/// Tree name
		tree: ConstString,
	},
	/// Attribute 'ID' is missing
	#[error("the tag '{tag}' is missing an 'ID' attribute")]
	MissingId {
		/// The affected tag
		tag: ConstString,
	},
	/// Name aka ID of root tree is missing
	#[error("name for the tree (Attribute 'ID') is missing")]
	MissingTreeName,
	/// Behavior is not registered
	#[error("the behavior '{behavior}' is not registered")]
	NotRegistered {
		/// The affected behavior
		behavior: ConstString,
	},
	/// The behavior does only allow and must have 1 child
	#[error("the behavior '{behavior}' must have exactly 1 child")]
	OneChild {
		/// The affected behavior
		behavior: ConstString,
	},
	/// Port not in defined port list of a behavior
	#[error("the port '{port}' is not in {behavior}'s  portlist")]
	PortInvalid {
		/// Name of the port
		port: ConstString,
		/// The affected behavior
		behavior: ConstString,
	},
	/// Invalid port type
	#[error("the value {value} is not valid as PortType")]
	PortType {
		/// The `PortType` literal that is not known
		value: ConstString,
	},
	/// Name for root element is wrong
	#[error("the name for the 'root' element must be 'root'")]
	RootName,
	/// Unknown attribute
	#[error("the attribute with key '{key}' is unknown")]
	UnknownAttribute {
		/// The attributes name
		key: ConstString,
	},
	/// Unsupported element
	#[error("the element '{tag}' under '{parent}' is not supported")]
	UnsupportedElement {
		/// The unsupproted tag name
		tag: ConstString,
		/// The parent element tag name
		parent: ConstString,
	},
	/// Attribute 'path' is missing
	#[cfg(feature = "std")]
	#[error("the tag '{tag}' is missing a 'path' attribute")]
	MissingPath {
		/// The affected tag
		tag: ConstString,
	},
	#[cfg(feature = "std")]
	#[error("file '{name}' could not be read: {cause}")]
	ReadFile {
		/// Filename
		name: ConstString,
		/// Stringified original error
		cause: ConstString,
	},
}