docbox_management_interface/
error.rs1use std::{
2 error::Error,
3 fmt::{Debug, Display},
4};
5
6#[derive(Debug, thiserror::Error)]
7pub enum ManagementError {
8 #[error("the target docbox service does not support the requested management operation")]
11 UnsupportedOperation,
12
13 #[error("failed to serialize command response")]
15 SerializeResponse(serde_json::Error),
16
17 #[error(transparent)]
19 Service(#[from] DynServiceError),
20}
21
22pub trait DocboxServiceError: Error + Send + Sync + 'static {
23 fn reason(&self) -> String {
25 self.to_string()
26 }
27
28 fn type_name(&self) -> &str {
31 std::any::type_name::<Self>()
32 }
33}
34
35pub struct DynServiceError {
36 inner: Box<dyn DocboxServiceError>,
37}
38
39impl Debug for DynServiceError {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 f.debug_tuple(self.inner.type_name())
42 .field(&self.inner)
43 .finish()
44 }
45}
46
47impl Display for DynServiceError {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 Display::fmt(&self.inner, f)
50 }
51}
52
53impl Error for DynServiceError {
54 fn cause(&self) -> Option<&dyn Error> {
55 Some(self.inner.as_ref())
56 }
57}
58
59impl<E> From<E> for DynServiceError
60where
61 E: DocboxServiceError,
62{
63 fn from(value: E) -> Self {
64 DynServiceError {
65 inner: Box::new(value),
66 }
67 }
68}