Skip to main content

cloud_sdk/diagnostics/
category.rs

1use crate::operation::{RequestIdPolicy, RetryEligibility};
2
3/// Finite payload-free client failure category.
4#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub enum DiagnosticErrorCategory {
6    /// Provider request preparation failed before transport access.
7    Preparation,
8    /// Execution authority was absent or invalid.
9    Authorization,
10    /// Endpoint identity or provider endpoint policy rejected dispatch.
11    Endpoint,
12    /// The concrete transport failed without exposing its error payload.
13    Transport,
14    /// Response staging or commit failed.
15    ResponseTransaction,
16    /// Provider-neutral response policy rejected the response.
17    ResponsePolicy,
18    /// Provider-owned checked decoding failed.
19    Decode,
20}
21
22/// Retry classification copied from validated operation metadata.
23#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
24pub enum DiagnosticRetryCategory {
25    /// Operation metadata forbids retry.
26    Ineligible,
27    /// Retry requires an explicit caller-owned policy.
28    ExplicitPolicy,
29}
30
31impl From<RetryEligibility> for DiagnosticRetryCategory {
32    fn from(value: RetryEligibility) -> Self {
33        match value {
34            RetryEligibility::Never => Self::Ineligible,
35            RetryEligibility::ExplicitPolicy => Self::ExplicitPolicy,
36        }
37    }
38}
39
40/// Request-identifier observation without identifier bytes.
41#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
42pub enum DiagnosticRequestId {
43    /// Operation policy discards request identifiers without exposing presence.
44    Discarded,
45    /// An admitted protected or retainable identifier was absent.
46    Absent,
47    /// An identifier is closure-scoped to checked response handling.
48    Protected,
49    /// An identifier may move only into cleanup-owning retained metadata.
50    Retainable,
51}
52
53impl DiagnosticRequestId {
54    pub(crate) const fn classify(policy: RequestIdPolicy, present: bool) -> Self {
55        match (policy, present) {
56            (RequestIdPolicy::Discard, _) => Self::Discarded,
57            (RequestIdPolicy::Protected | RequestIdPolicy::Retain, false) => Self::Absent,
58            (RequestIdPolicy::Protected, true) => Self::Protected,
59            (RequestIdPolicy::Retain, true) => Self::Retainable,
60        }
61    }
62}