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("invalid plugin configuration: {0}")]
40    Configuration(#[source] Arc<crate::ConfigError>),
41
42    #[error("plugin lifecycle machinery failed: {0}")]
43    Plugin(#[source] Arc<P::Error>),
44
45    #[error("plugin operation inventory failed: {0}")]
46    Inventory(#[source] Arc<crate::inventory::operations::Error>),
47
48    #[error("plugin operation table failed: {0}")]
49    Serving(#[source] Arc<ServingError>),
50
51    #[error("SDK generation context must be empty or exactly 32 nonzero bytes")]
52    GenerationContext,
53
54    #[error("plugin lifecycle state is unavailable for this phase")]
55    Phase,
56
57    #[error("plugin lifecycle machinery panicked")]
58    Panicked,
59
60    #[error("plugin lifecycle state lock is poisoned")]
61    Poisoned,
62}
63
64/* === Traits === */
65
66/* === Implementations === */
67
68impl<P: Plugin> std::fmt::Debug for Error<P> {
69    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70        match self {
71            Self::Configuration(error) => formatter.debug_tuple("Configuration").field(error).finish(),
72            Self::Plugin(error) => formatter.debug_tuple("Plugin").field(error).finish(),
73            Self::Inventory(error) => formatter.debug_tuple("Inventory").field(error).finish(),
74            Self::Serving(error) => formatter.debug_tuple("Serving").field(error).finish(),
75            Self::GenerationContext => formatter.write_str("GenerationContext"),
76            Self::Phase => formatter.write_str("Phase"),
77            Self::Panicked => formatter.write_str("Panicked"),
78            Self::Poisoned => formatter.write_str("Poisoned"),
79        }
80    }
81}
82
83impl<P: Plugin> Clone for Error<P> {
84    fn clone(&self) -> Self {
85        match self {
86            Self::Configuration(error) => Self::Configuration(Arc::clone(error)),
87            Self::Plugin(error) => Self::Plugin(Arc::clone(error)),
88            Self::Inventory(error) => Self::Inventory(Arc::clone(error)),
89            Self::Serving(error) => Self::Serving(Arc::clone(error)),
90            Self::GenerationContext => Self::GenerationContext,
91            Self::Phase => Self::Phase,
92            Self::Panicked => Self::Panicked,
93            Self::Poisoned => Self::Poisoned,
94        }
95    }
96}
97
98/* === Public Functions === */
99
100/* === Private Functions === */
101
102/* === Tests === */