1use std::sync::Arc;
18
19use crate::operations::ServingError;
23use crate::plugin::Plugin;
24
25#[derive(thiserror::Error)]
36pub enum Error<P: Plugin> {
37 #[error(transparent)]
38 Resource(Arc<crate::ResourceError>),
39
40 #[error("invalid plugin configuration: {0}")]
41 Configuration(#[source] Arc<crate::ConfigError>),
42
43 #[error("plugin lifecycle machinery failed: {0}")]
44 Plugin(#[source] Arc<P::Error>),
45
46 #[error("plugin operation inventory failed: {0}")]
47 Inventory(#[source] Arc<crate::inventory::operations::Error>),
48
49 #[error("plugin operation table failed: {0}")]
50 Serving(#[source] Arc<ServingError>),
51
52 #[error("SDK generation context must be empty or exactly 32 nonzero bytes")]
53 GenerationContext,
54
55 #[error("plugin lifecycle state is unavailable for this phase")]
56 Phase,
57
58 #[error("plugin lifecycle machinery panicked")]
59 Panicked,
60
61 #[error("plugin lifecycle state lock is poisoned")]
62 Poisoned,
63}
64
65impl<P: Plugin> std::fmt::Debug for Error<P> {
70 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71 match self {
72 Self::Resource(error) => formatter.debug_tuple("Resource").field(error).finish(),
73 Self::Configuration(error) => formatter.debug_tuple("Configuration").field(error).finish(),
74 Self::Plugin(error) => formatter.debug_tuple("Plugin").field(error).finish(),
75 Self::Inventory(error) => formatter.debug_tuple("Inventory").field(error).finish(),
76 Self::Serving(error) => formatter.debug_tuple("Serving").field(error).finish(),
77 Self::GenerationContext => formatter.write_str("GenerationContext"),
78 Self::Phase => formatter.write_str("Phase"),
79 Self::Panicked => formatter.write_str("Panicked"),
80 Self::Poisoned => formatter.write_str("Poisoned"),
81 }
82 }
83}
84
85impl<P: Plugin> Clone for Error<P> {
86 fn clone(&self) -> Self {
87 match self {
88 Self::Resource(error) => Self::Resource(Arc::clone(error)),
89 Self::Configuration(error) => Self::Configuration(Arc::clone(error)),
90 Self::Plugin(error) => Self::Plugin(Arc::clone(error)),
91 Self::Inventory(error) => Self::Inventory(Arc::clone(error)),
92 Self::Serving(error) => Self::Serving(Arc::clone(error)),
93 Self::GenerationContext => Self::GenerationContext,
94 Self::Phase => Self::Phase,
95 Self::Panicked => Self::Panicked,
96 Self::Poisoned => Self::Poisoned,
97 }
98 }
99}
100
101