aster_forge_cloud_files_macos_bridge/
error.rs1use aster_forge_cloud_files_core::{CloudBackendError, CloudBackendErrorKind, SessionState};
4
5pub type Result<T> = std::result::Result<T, MacosBridgeError>;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[repr(i32)]
11pub enum MacosErrorCode {
12 Success = 0,
14 NotFound = 1,
16 NotAuthenticated = 2,
18 PermissionDenied = 3,
20 VersionOutOfDate = 4,
22 TryAgain = 5,
24 NotSupported = 6,
26 InvalidArgument = 7,
28 SyncAnchorExpired = 8,
30 Cancelled = 9,
32 ProviderNotFound = 10,
34 Internal = 11,
36}
37
38#[derive(Debug, thiserror::Error)]
40pub enum MacosBridgeError {
41 #[error("invalid macOS File Provider identifier: {reason}")]
43 InvalidIdentifier {
44 reason: &'static str,
46 },
47 #[error("File Provider system container cannot be decoded as a cloud item")]
49 SystemContainerIsNotItem,
50 #[error("invalid macOS File Provider item version: {reason}")]
52 InvalidItemVersion {
53 reason: &'static str,
55 },
56 #[error("invalid cloud backend response: {reason}")]
58 InvalidBackendResponse {
59 reason: &'static str,
61 },
62 #[error("unsupported File Provider system container for enumeration")]
64 UnsupportedSystemContainer,
65 #[error("stale extension generation: expected {expected}, got {actual}")]
67 StaleSessionGeneration {
68 expected: u64,
70 actual: u64,
72 },
73 #[error("extension session is not accepting requests: {state:?}")]
75 SessionNotAccepting {
76 state: SessionState,
78 },
79 #[error("invalid extension lifecycle transition from {from:?} to {to:?}")]
81 InvalidSessionTransition {
82 from: SessionState,
84 to: SessionState,
86 },
87 #[error("active File Provider request count overflow")]
89 ActiveRequestCountOverflow,
90 #[error("invalid macOS bridge FFI input: {reason}")]
92 InvalidFfiInput {
93 reason: &'static str,
95 },
96 #[error("panic contained at macOS bridge FFI boundary")]
98 FfiPanic,
99 #[error(transparent)]
101 Backend(#[from] CloudBackendError),
102}
103
104impl MacosBridgeError {
105 #[must_use]
107 pub const fn error_code(&self) -> MacosErrorCode {
108 match self {
109 Self::InvalidIdentifier { .. }
110 | Self::SystemContainerIsNotItem
111 | Self::InvalidItemVersion { .. }
112 | Self::InvalidFfiInput { .. } => MacosErrorCode::InvalidArgument,
113 Self::UnsupportedSystemContainer => MacosErrorCode::NotSupported,
114 Self::StaleSessionGeneration { .. } => MacosErrorCode::ProviderNotFound,
115 Self::SessionNotAccepting { .. } | Self::InvalidSessionTransition { .. } => {
116 MacosErrorCode::ProviderNotFound
117 }
118 Self::ActiveRequestCountOverflow
119 | Self::InvalidBackendResponse { .. }
120 | Self::FfiPanic => MacosErrorCode::Internal,
121 Self::Backend(error) => backend_error_code(error.kind()),
122 }
123 }
124}
125
126#[must_use]
128pub const fn backend_error_code(kind: CloudBackendErrorKind) -> MacosErrorCode {
129 match kind {
130 CloudBackendErrorKind::NotFound => MacosErrorCode::NotFound,
131 CloudBackendErrorKind::AuthenticationRequired => MacosErrorCode::NotAuthenticated,
132 CloudBackendErrorKind::PermissionDenied => MacosErrorCode::PermissionDenied,
133 CloudBackendErrorKind::Conflict | CloudBackendErrorKind::PreconditionFailed => {
134 MacosErrorCode::VersionOutOfDate
135 }
136 CloudBackendErrorKind::InvalidRequest => MacosErrorCode::InvalidArgument,
137 CloudBackendErrorKind::RateLimited | CloudBackendErrorKind::TemporarilyUnavailable => {
138 MacosErrorCode::TryAgain
139 }
140 CloudBackendErrorKind::Unsupported => MacosErrorCode::NotSupported,
141 CloudBackendErrorKind::InvalidResponse | CloudBackendErrorKind::Internal => {
142 MacosErrorCode::Internal
143 }
144 }
145}