dimas_core/
error.rs

1// Copyright © 2023 Stephan Kunz
2
3//! core errors
4//!
5
6#[doc(hidden)]
7extern crate alloc;
8
9#[cfg(feature = "std")]
10extern crate std;
11
12// region:		--- modules
13#[cfg(doc)]
14use super::enums::OperationState;
15use alloc::{boxed::Box, string::String};
16use thiserror::Error;
17// endregion:	--- modules
18
19// region:		--- types
20/// Result type alias.
21pub type Result<T> = core::result::Result<T, Box<dyn core::error::Error + Send + Sync + 'static>>;
22// endregion:	--- types
23
24// region:		--- Error
25/// `dimas-core` error type.
26#[derive(Error, Debug)]
27pub enum Error {
28	/// decoding failed
29	#[error("decoding failed: reason {source}")]
30	Decoding {
31		/// the original bitcode error
32		source: Box<dyn core::error::Error + Send + Sync>,
33	},
34	/// sending reply failed
35	#[error("sending a reply failed: reason {source}")]
36	Reply {
37		/// the original zenoh error
38		source: Box<dyn core::error::Error + Send + Sync>,
39	},
40	/// empty request
41	#[error("query was empty")]
42	EmptyQuery,
43	/// Not available/implemented
44	#[error("no implementation available")]
45	NotImplemented,
46	/// An unknown [`OperationState`] is given
47	#[error("the operation state {state} is unknown")]
48	UnknownOperationState {
49		/// name of the operation state
50		state: String,
51	},
52}
53// region:		--- Error
54
55#[cfg(test)]
56mod tests {
57	use super::*;
58
59	// check, that the auto traits are available
60	const fn is_normal<T: Sized + Send + Sync>() {}
61
62	#[test]
63	const fn normal_types() {
64		is_normal::<Error>();
65	}
66}