Skip to main content

harmos_sdk/operations/
startup.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10// Typed Startup Configuration Errors
11
12/* === Modules === */
13
14/* === Re-Exports === */
15
16/* === Imports === */
17
18// Standard Library Imports
19
20// Third Party Imports
21
22// Local Imports
23use super::ServingError;
24
25/* === Constants === */
26
27/* === Macros === */
28
29/* === Type Aliases === */
30
31/* === Structs === */
32
33/* === Enums === */
34
35#[derive(Debug, thiserror::Error)]
36pub enum StartupError {
37    #[error("resource `{name}` is already configured")]
38    DuplicateResource { name: &'static str },
39
40    #[error("catalog `{name}` is already configured")]
41    DuplicateCatalog { name: &'static str },
42
43    #[error("operation `{operation}` requires missing resource `{resource}`")]
44    MissingResource { operation: String, resource: &'static str },
45
46    #[error("lane `{lane}` is not declared by the application")]
47    UnknownLane { lane: &'static str },
48
49    #[error("startup configuration has {} errors: {errors:?}", .errors.len())]
50    Multiple { errors: Vec<StartupError> },
51
52    #[error("operation binding failed: {source}")]
53    Binding {
54        #[source]
55        source: Box<ServingError>,
56    },
57
58    #[error("runtime startup failed: {source}")]
59    Runtime {
60        #[source]
61        source: Box<dyn std::error::Error + Send + Sync>,
62    },
63}
64
65/* === Traits === */
66
67/* === Implementations === */
68
69impl StartupError {
70    pub fn aggregate(mut errors: Vec<Self>) -> Option<Self> {
71        match errors.len() {
72            0 => None,
73            1 => errors.pop(),
74            _ => Some(Self::Multiple { errors }),
75        }
76    }
77}
78
79/* === Public Functions === */
80
81/* === Private Functions === */
82
83/* === Tests === */