Skip to main content

harmos_sdk/
error.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10// Plugin Lifecycle Errors
11
12/* === Modules === */
13
14/* === Re-Exports === */
15
16/* === Imports === */
17
18// Standard Library Imports
19use std::sync::Arc;
20
21// Third Party Imports
22
23// Local Imports
24use crate::operations::ServingError;
25use crate::plugin::Plugin;
26
27/* === Constants === */
28
29/* === Macros === */
30
31/* === Type Aliases === */
32
33/* === Structs === */
34
35/* === Enums === */
36
37#[derive(thiserror::Error)]
38pub enum Error<P: Plugin> {
39    #[error(transparent)]
40    Resource(Arc<crate::ResourceError>),
41
42    #[error("invalid plugin configuration: {0}")]
43    Configuration(#[source] Arc<crate::ConfigError>),
44
45    #[error("plugin lifecycle machinery failed: {0}")]
46    Plugin(#[source] Arc<P::Error>),
47
48    #[error("plugin operation inventory failed: {0}")]
49    Inventory(#[source] Arc<crate::inventory::operations::Error>),
50
51    #[error("plugin operation table failed: {0}")]
52    Serving(#[source] Arc<ServingError>),
53
54    #[error("SDK generation context must be empty or exactly 32 nonzero bytes")]
55    GenerationContext,
56
57    #[error("plugin lifecycle state is unavailable for this phase")]
58    Phase,
59
60    #[error("plugin lifecycle machinery panicked")]
61    Panicked,
62
63    #[error("plugin lifecycle state lock is poisoned")]
64    Poisoned,
65}
66
67/* === Traits === */
68
69/* === Implementations === */
70
71impl<P: Plugin> std::fmt::Debug for Error<P> {
72    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73        match self {
74            Self::Resource(error) => formatter.debug_tuple("Resource").field(error).finish(),
75            Self::Configuration(error) => formatter.debug_tuple("Configuration").field(error).finish(),
76            Self::Plugin(error) => formatter.debug_tuple("Plugin").field(error).finish(),
77            Self::Inventory(error) => formatter.debug_tuple("Inventory").field(error).finish(),
78            Self::Serving(error) => formatter.debug_tuple("Serving").field(error).finish(),
79            Self::GenerationContext => formatter.write_str("GenerationContext"),
80            Self::Phase => formatter.write_str("Phase"),
81            Self::Panicked => formatter.write_str("Panicked"),
82            Self::Poisoned => formatter.write_str("Poisoned"),
83        }
84    }
85}
86
87impl<P: Plugin> Clone for Error<P> {
88    fn clone(&self) -> Self {
89        match self {
90            Self::Resource(error) => Self::Resource(Arc::clone(error)),
91            Self::Configuration(error) => Self::Configuration(Arc::clone(error)),
92            Self::Plugin(error) => Self::Plugin(Arc::clone(error)),
93            Self::Inventory(error) => Self::Inventory(Arc::clone(error)),
94            Self::Serving(error) => Self::Serving(Arc::clone(error)),
95            Self::GenerationContext => Self::GenerationContext,
96            Self::Phase => Self::Phase,
97            Self::Panicked => Self::Panicked,
98            Self::Poisoned => Self::Poisoned,
99        }
100    }
101}
102
103/* === Public Functions === */
104
105/* === Private Functions === */
106
107/* === Tests === */