crazyflie_lib/
error.rs

1use std::array::TryFromSliceError;
2
3use crazyflie_link::Packet;
4use futures::task::SpawnError;
5
6/// [Result] alias for return types of the crate API
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Error enum type
10#[derive(Debug)]
11pub enum Error {
12    /// Protocol version not supported, you need to update either the lib or the Crazyflie.
13    ///
14    /// see [the crate documentation](crate#compatibility) for more information.
15    ProtocolVersionNotSupported,
16    /// Unexpected protocol error. The String contains the reason.
17    ProtocolError(String),
18    /// Parameter subsystem error. The String contains the reason.
19    ParamError(String),
20    /// Log Subsystem error. The String contains the reason.
21    LogError(String),
22    /// [Value](crate::Value) conversion error. The String contains the reason.
23    ConversionError(String),
24    /// Crazyflie link configuration error. Returns the [error from the Link](crazyflie_link::Error).
25    LinkError(crazyflie_link::Error),
26    /// The Crazyflie object is currently disconnected.
27    Disconnected,
28    /// Variable not found in TOC.
29    VariableNotFound,
30    /// Error with the async executors.
31    SystemError(String),
32    /// App channel packets should be no larger than [APPCHANNEL_MTU](crate::subsystems::platform::APPCHANNEL_MTU)
33    AppchannelPacketTooLarge,
34}
35
36impl std::fmt::Display for Error {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        f.write_fmt(format_args!("Foo {}", self))
39    }
40}
41
42impl std::error::Error for Error {}
43
44impl From<TryFromSliceError> for Error {
45    fn from(e: TryFromSliceError) -> Self {
46        Self::ConversionError(format!("{:?}", e))
47    }
48}
49
50impl From<crazyflie_link::Error> for Error {
51    fn from(error: crazyflie_link::Error) -> Self {
52        Self::LinkError(error)
53    }
54}
55
56impl From<SpawnError> for Error {
57    fn from(error: SpawnError) -> Self {
58        Self::SystemError(format!("{}", error))
59    }
60}
61
62impl From<flume::RecvError> for Error {
63    fn from(_: flume::RecvError) -> Self {
64        self::Error::Disconnected
65    }
66}
67
68impl From<flume::SendError<Packet>> for Error {
69    fn from(_: flume::SendError<Packet>) -> Self {
70        self::Error::Disconnected
71    }
72}