1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/// Error enum for agent_tk
#[derive(thiserror::Error, Debug)]
#[allow(missing_docs)]
pub enum Error
{
  #[error("UTF8 Error: '{0}'")]
  Utf8Error(#[from] std::str::Utf8Error),
  #[error("MQTT Connection Error: '{0}'")]
  #[cfg(feature = "mqtt")]
  MQTTConnectionError(#[from] rumqttc::v5::ConnectionError),
  #[error("Capability '{0}' is unknown.")]
  UnknownCapability(&'static str),
  #[error("Capability '{0}' already defined.")]
  DuplicateCapability(&'static str),
  #[error("An error occured during transport: '{0}'.")]
  TransportError(String),
  #[error("Invalid task type: {0}.")]
  InvalidTaskType(String),
  #[error("Unknown task type: {0}.")]
  UnknownTaskType(String),
  #[error("State '{0}' is unknown.")]
  UnknownState(&'static str),
  #[error("State '{0}' already defined.")]
  DuplicateState(&'static str),
  #[error("The execution failed: {0}.")]
  ExecutionFailed(String),
  #[error("The task '{0}' cannot be executed.")]
  CannotExecute(String),
  #[error("No executor.")]
  NoExecutor(),
  #[error("Invalid collection: {0}.")]
  InvalidCollection(String),
  #[error("Unknown value in collection {0} with key {1}.")]
  UnknownValue(String, String),
  #[error("Serialization error: {0}")]
  SerializationError(String),
  #[error("Deserialization error: {0}")]
  DeserializationError(String),
  #[error("Mutex error: {0}")]
  MutexError(String),
  #[error("Runtime error: {0}")]
  Runtime(String),
  #[error("Invalid UUID: {0} with error {1}")]
  InvalidUuid(String, String),
  #[error("Unimplemented: {0}.")]
  Unimplemented(&'static str),
}

impl<'a, T> From<std::sync::PoisonError<std::sync::MutexGuard<'a, T>>> for Error
{
  fn from(value: std::sync::PoisonError<std::sync::MutexGuard<'a, T>>) -> Self
  {
    Error::MutexError(value.to_string())
  }
}

impl From<serde_json::Error> for Error
{
  fn from(value: serde_json::Error) -> Self
  {
    Error::SerializationError(value.to_string())
  }
}

impl From<yaaral::NoError> for Error
{
  fn from(value: yaaral::NoError) -> Self
  {
    Error::Unimplemented("yaaral::NoError should never trigger.")
  }
}