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