Skip to main content

wire/
message_status.rs

1// SPDX-License-Identifier: Apache-2.0
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Status {
6    pub code: StatusCode,
7    pub message: String,
8    pub progress: Option<f32>,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
12pub enum StatusCode {
13    Progress,
14    Success,
15    Warning,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct Error {
20    pub code: ErrorCode,
21    pub message: String,
22    pub details: Option<String>,
23}
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
26pub enum ErrorCode {
27    General,
28    InvalidArgument,
29    NotFound,
30    PermissionDenied,
31    Network,
32    Protocol,
33    Server,
34}
35
36/// Stable outcome vocabulary for a failed hosted call. This mirrors the
37/// governed API contract without depending on generated protobuf types.
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
39pub enum RemoteFailureCode {
40    Unspecified,
41    Cancelled,
42    Unknown,
43    InvalidArgument,
44    DeadlineExceeded,
45    NotFound,
46    AlreadyExists,
47    PermissionDenied,
48    ResourceExhausted,
49    FailedPrecondition,
50    Aborted,
51    OutOfRange,
52    Unimplemented,
53    Internal,
54    Unavailable,
55    DataLoss,
56    Unauthenticated,
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
60pub struct RemoteDuration {
61    pub seconds: i64,
62    pub nanos: i32,
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
66pub struct RemoteTimestamp {
67    pub seconds: i64,
68    pub nanos: i32,
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
72pub enum RemoteCursorReason {
73    Unspecified,
74    Stale,
75    Expired,
76}
77
78#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
79pub struct RemoteCursorFailure {
80    pub reason: RemoteCursorReason,
81    pub expired_at: Option<RemoteTimestamp>,
82    pub restart_cursor: String,
83}
84
85/// Machine-readable hosted failure details retained across the transport seam.
86/// Unknown details stay lossless so a newer server does not collapse them to
87/// prose when talking to an older client.
88#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
89pub enum RemoteFailureDetail {
90    Retry {
91        retry_after: Option<RemoteDuration>,
92    },
93    Conflict {
94        resource: String,
95        expected_version: String,
96        actual_version: String,
97    },
98    Cursor(RemoteCursorFailure),
99    CapabilityRequirement {
100        capabilities: Vec<String>,
101    },
102    PolicyDenial {
103        policy_id: String,
104        rule: String,
105        human_verification_can_override: bool,
106    },
107    Stream {
108        code: RemoteFailureCode,
109        message: String,
110        retry_after: Option<RemoteDuration>,
111        cursor: Option<RemoteCursorFailure>,
112    },
113    Unknown {
114        type_url: String,
115        value: Vec<u8>,
116    },
117}