u280_hardware_promoter/
failure.rs1use serde::Serialize;
4use std::fmt;
5
6#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
8#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
9pub enum FailureCode {
10 InputFs,
12 InputChanged,
14 Schema,
16 Noncanonical,
18 PrematureClaim,
20 RouteUnaccepted,
22 RouteTiming,
24 RouteResource,
26 TransportInvalid,
28 OracleReceipt,
30 OracleResult,
32 OracleNegative,
34 IdentityJoin,
36 CoordinationChain,
38 CoordinationReplay,
40 PerformancePopulation,
42 PerformanceThreshold,
44 StateBurn,
46 Publication,
48}
49
50impl FailureCode {
51 #[must_use]
53 pub const fn as_str(self) -> &'static str {
54 match self {
55 Self::InputFs => "INPUT_FS",
56 Self::InputChanged => "INPUT_CHANGED",
57 Self::Schema => "SCHEMA",
58 Self::Noncanonical => "NONCANONICAL",
59 Self::PrematureClaim => "PREMATURE_CLAIM",
60 Self::RouteUnaccepted => "ROUTE_UNACCEPTED",
61 Self::RouteTiming => "ROUTE_TIMING",
62 Self::RouteResource => "ROUTE_RESOURCE",
63 Self::TransportInvalid => "TRANSPORT_INVALID",
64 Self::OracleReceipt => "ORACLE_RECEIPT",
65 Self::OracleResult => "ORACLE_RESULT",
66 Self::OracleNegative => "ORACLE_NEGATIVE",
67 Self::IdentityJoin => "IDENTITY_JOIN",
68 Self::CoordinationChain => "COORDINATION_CHAIN",
69 Self::CoordinationReplay => "COORDINATION_REPLAY",
70 Self::PerformancePopulation => "PERFORMANCE_POPULATION",
71 Self::PerformanceThreshold => "PERFORMANCE_THRESHOLD",
72 Self::StateBurn => "STATE_BURN",
73 Self::Publication => "PUBLICATION",
74 }
75 }
76}
77
78impl fmt::Display for FailureCode {
79 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
80 formatter.write_str(self.as_str())
81 }
82}
83
84#[derive(Clone, Debug, Eq, PartialEq)]
86pub struct PromotionError {
87 code: FailureCode,
88 message: String,
89}
90
91impl PromotionError {
92 #[must_use]
94 pub fn new(code: FailureCode, message: impl Into<String>) -> Self {
95 Self {
96 code,
97 message: message.into(),
98 }
99 }
100
101 #[must_use]
103 pub const fn code(&self) -> FailureCode {
104 self.code
105 }
106
107 #[must_use]
109 pub fn message(&self) -> &str {
110 &self.message
111 }
112}
113
114impl fmt::Display for PromotionError {
115 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
116 write!(formatter, "{}: {}", self.code, self.message)
117 }
118}
119
120impl std::error::Error for PromotionError {}
121
122pub type PromotionResult<T> = std::result::Result<T, PromotionError>;