dimas_com/
error.rs

1// Copyright © 2024 Stephan Kunz
2
3//! `dimas-com` errors
4
5#[doc(hidden)]
6extern crate alloc;
7
8#[cfg(feature = "std")]
9extern crate std;
10
11// region:		--- modules
12#[cfg(doc)]
13use crate::zenoh::{Communicator, Observable, Observer, Publisher, Querier, Queryable, Subscriber};
14use alloc::{boxed::Box, string::String};
15#[cfg(doc)]
16use dimas_core::message_types::Message;
17use thiserror::Error;
18#[cfg(doc)]
19use zenoh::query::Query;
20// endregion:	--- modules
21
22// region:		--- Error
23/// `dimas-com` error type.
24#[derive(Error, Debug)]
25pub enum Error {
26	/// Not available/implemented
27	#[error("no implementation available")]
28	NotImplemented,
29	/// no communicator for that id
30	#[error("no communicator with id: {0}")]
31	NoCommunicator(String),
32	/// No zenoh available/implemented
33	#[error("no zenoh session available")]
34	NoZenohSession,
35	/// Invalid selector
36	#[error("invalid selector for '{0}'")]
37	InvalidSelector(String),
38	/// Creation of the [`Communicator`] was not possible
39	#[error("creation of zenoh session failed with reason: {source}")]
40	CreateCommunicator {
41		/// the original zenoh error
42		source: Box<dyn core::error::Error + Send + Sync>,
43	},
44	/// Accessing a [`Publisher`] failed
45	#[error("getting the publisher failed")]
46	AccessPublisher,
47	/// A Mutex is poisoned.
48	#[error("a Mutex poison error happened in {0}")]
49	MutexPoison(String),
50	/// Publishing a [`Message`] via `put` failed
51	#[error("publishing a put message failed with reason: {source}")]
52	PublishingPut {
53		/// the original zenoh error
54		source: Box<dyn core::error::Error + Send + Sync>,
55	},
56	/// Publishing a [`Message`] via `delete` failed
57	#[error("publishing a delete message failed with reason: {source}")]
58	PublishingDelete {
59		/// the original zenoh error
60		source: Box<dyn core::error::Error + Send + Sync>,
61	},
62	/// Creation of a [`Query`] failed
63	#[error("creation of a query failed with reason: {source}")]
64	QueryCreation {
65		/// the original zenoh error
66		source: Box<dyn core::error::Error + Send + Sync>,
67	},
68	/// Callback of a [`Query`] failed
69	#[error("callback of query failed with reason: {source}")]
70	QueryCallback {
71		/// the original callback error
72		source: Box<dyn core::error::Error + Send + Sync>,
73	},
74	/// read access failed
75	#[error("read storage for {0} failed")]
76	ReadAccess(String),
77	/// write access failed
78	#[error("write storage for {0} failed")]
79	ModifyStruct(String),
80	/// Creation of a [`Subscriber`] failed
81	#[error("creation of a subscriber failed with reason: {source}")]
82	SubscriberCreation {
83		/// the original zenoh error
84		source: Box<dyn core::error::Error + Send + Sync>,
85	},
86	/// Callback of a [`Subscriber`] failed
87	#[error("callback of subscriber failed with reason: {source}")]
88	SubscriberCallback {
89		/// the original callback error
90		source: Box<dyn core::error::Error + Send + Sync>,
91	},
92	/// Accessing the [`Querier`] failed.
93	#[error("accessing querier '{selector}' failed")]
94	AccessingQuerier {
95		/// query selector
96		selector: String,
97	},
98	/// Accessing the [`Queryable`] failed.
99	#[error("accessing queryable '{selector}' failed")]
100	AccessingQueryable {
101		/// query selector
102		selector: String,
103	},
104	/// Accessing the [`Observable`] for a [`Observer`] failed.
105	#[error("accessing observable '{selector}' failed")]
106	AccessingObservable {
107		/// observables selector
108		selector: String,
109	},
110	/// Found unknown communication protocol
111	#[error("the protocol '{protocol}' is unknown")]
112	UnknownProtocol {
113		/// protocol name
114		protocol: String,
115	},
116}
117// region:		--- Error