dimas_core/
error.rs

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright © 2023 Stephan Kunz

//! The `DiMAS` specific error enum `DimasError` together with a
//! type alias for [`core::result::Result`] to write only `Result<T>`.
//!

#[cfg(feature = "std")]
extern crate std;

// region:		--- modules
#[cfg(feature = "std")]
use std::prelude::rust_2021::*;
// endregion:	--- modules

// region:		--- types
/// Type alias for `core::result::Result` to ease up implementation
pub type Result<T> = core::result::Result<T, Box<dyn core::error::Error + Send + Sync + 'static>>;
// endregion:	--- types

// region:    --- DimasError
/// `DiMAS` Error type
#[non_exhaustive]
#[derive(thiserror::Error, Debug)]
#[allow(clippy::module_name_repetitions)]
pub enum DimasError {
	/// this error should never happen
	#[error("should not happen")]
	ShouldNotHappen,
	/// The `put` of a `Publisher` failed
	#[error("Publisher 'put' failed")]
	Put,
	/// The `delete` of a `Publisher` failed
	#[error("Publisher 'delete' failed")]
	Delete,
	/// The `get` of a `Query` failed
	#[error("Query 'get' failed")]
	Get,
	/// Encoding of message failed
	#[error("message encoding failed")]
	Encoding,
	/// Converting of message failed
	#[error("converting value into 'Vec<u8>' failed")]
	ConvertingValue,
	/// Decoding of message failed
	#[error("message decoding failed")]
	Decoding,
	/// Decoding of message failed
	#[error("no message received")]
	NoMessage,
	/// Read access to properties failed
	#[error("read of properties failed")]
	ReadProperties,
	/// Write access to properties failed
	#[error("write of properties failed")]
	WriteProperties,
	/// Lock on callback failed
	#[error("could not execute callback")]
	ExecuteCallback,

	/// Invalid `OperationState`
	#[error("invalid OperationState {0}")]
	OperationState(String),
	/// File not found
	#[error("could not find file: {0}")]
	FileNotFound(String),
	/// Modifying context failed
	#[error("modifying context for {0} failed")]
	ModifyContext(String),
	/// The `set_state` failed
	#[error("setting the 'OperationState' failed")]
	ManageState,
	/// Reading context failed
	#[error("reading context for {0} failed")]
	ReadContext(String),

	/// `zenoh` session creation failed
	#[error("creation of zenoh session failed with {0}")]
	CreateSession(#[source] Box<dyn core::error::Error + Send + Sync + 'static>),
	/// `zenoh` activate sending liveliness failed
	#[error("activation of zenoh liveliness failed with {0}")]
	ActivateLiveliness(#[source] Box<dyn core::error::Error + Send + Sync + 'static>),
	/// `zenoh` publisher  declaration failed
	#[error("declaration of zenoh publisher failed with {0}")]
	DeclarePublisher(#[source] Box<dyn core::error::Error + Send + Sync + 'static>),

	// should be last line
	/// auto conversion for boxed `core::error::Error`
	#[error(transparent)]
	StdError(#[from] Box<dyn core::error::Error + Send + Sync + 'static>),
} // endregion: --- DimasError

#[cfg(test)]
mod tests {
	use super::*;

	// check, that the auto traits are available
	const fn is_normal<T: Sized + Send + Sync>() {}

	#[test]
	const fn normal_types() {
		is_normal::<DimasError>();
	}
}