1use snafu::prelude::*;
4
5#[derive(Debug, Snafu)]
7#[snafu(visibility(pub))]
8pub enum AnytypeGrpcError {
9 #[snafu(display("Auth error: {source}"))]
11 Auth { source: AuthError },
12
13 #[snafu(display("Config error: {source}"))]
15 Config { source: ConfigError },
16
17 #[snafu(display("View error: {source}"))]
19 View { source: ViewError },
20
21 #[snafu(display("Backup error: {source}"))]
23 Backup { source: BackupError },
24
25 #[snafu(display("Transport error: {source}"))]
27 Transport { source: tonic::transport::Error },
28}
29
30#[derive(Debug, Snafu)]
32#[snafu(visibility(pub))]
33pub enum AuthError {
34 #[snafu(display("Transport error: {source}"))]
36 Status { source: tonic::Status },
37
38 #[snafu(display("API error ({code}): {description}"))]
40 Api { code: i32, description: String },
41
42 #[snafu(display("Create session returned empty token"))]
44 EmptyToken,
45
46 #[snafu(display("Invalid metadata value: {source}"))]
48 InvalidMetadata {
49 source: tonic::metadata::errors::InvalidMetadataValue,
50 },
51}
52
53#[derive(Debug, Snafu)]
55#[snafu(visibility(pub))]
56pub enum ConfigError {
57 #[snafu(display("I/O error: {source}"))]
59 Io { source: std::io::Error },
60
61 #[snafu(display("Parse error: {source}"))]
63 Parse { source: serde_json::Error },
64
65 #[snafu(display("HOME environment variable not set"))]
67 MissingHome,
68}
69
70#[derive(Debug, Snafu)]
72#[snafu(visibility(pub))]
73pub enum ViewError {
74 #[snafu(display("Transport error: {source}"))]
76 Rpc { source: tonic::Status },
77
78 #[snafu(display("API error ({code}): {description}"))]
80 ApiResponse { code: i32, description: String },
81
82 #[snafu(display("Object view missing in response"))]
84 MissingObjectView,
85
86 #[snafu(display("Dataview block not found for view id {view_id}"))]
88 MissingDataviewBlock { view_id: String },
89
90 #[snafu(display("View id {view_id} not found"))]
92 MissingView { view_id: String },
93
94 #[snafu(display("View id {view_id} is not a supported view (type {actual})"))]
96 NotSupportedView { view_id: String, actual: i32 },
97}
98
99#[derive(Debug, Snafu)]
101#[snafu(visibility(pub))]
102pub enum BackupError {
103 #[snafu(display("Transport error: {source}"))]
105 BackupRpc { source: tonic::Status },
106
107 #[snafu(display("API error ({code}): {description}"))]
109 BackupApiResponse { code: i32, description: String },
110
111 #[snafu(display("Auth error: {source}"))]
113 BackupAuth { source: AuthError },
114
115 #[snafu(display("Invalid backup options: {message}"))]
117 InvalidOptions { message: String },
118
119 #[snafu(display("Failed to resolve space name for {space_id}: {message}"))]
121 SpaceNameLookup { space_id: String, message: String },
122
123 #[snafu(display("Backup response missing export path"))]
125 MissingExportPath,
126
127 #[snafu(display("I/O error for {path:?}: {source}"))]
129 BackupIo {
130 path: std::path::PathBuf,
131 source: std::io::Error,
132 },
133
134 #[snafu(display("Failed to move backup from {from:?} to {to:?}: {source}"))]
136 BackupMove {
137 from: std::path::PathBuf,
138 to: std::path::PathBuf,
139 source: std::io::Error,
140 },
141}
142
143impl From<tonic::Status> for AuthError {
145 fn from(source: tonic::Status) -> Self {
146 AuthError::Status { source }
147 }
148}
149
150impl From<tonic::metadata::errors::InvalidMetadataValue> for AuthError {
151 fn from(source: tonic::metadata::errors::InvalidMetadataValue) -> Self {
152 AuthError::InvalidMetadata { source }
153 }
154}
155
156impl From<std::io::Error> for ConfigError {
158 fn from(source: std::io::Error) -> Self {
159 ConfigError::Io { source }
160 }
161}
162
163impl From<serde_json::Error> for ConfigError {
164 fn from(source: serde_json::Error) -> Self {
165 ConfigError::Parse { source }
166 }
167}
168
169impl From<tonic::Status> for ViewError {
171 fn from(source: tonic::Status) -> Self {
172 ViewError::Rpc { source }
173 }
174}
175
176impl From<tonic::Status> for BackupError {
178 fn from(source: tonic::Status) -> Self {
179 BackupError::BackupRpc { source }
180 }
181}
182
183impl From<AuthError> for BackupError {
184 fn from(source: AuthError) -> Self {
185 BackupError::BackupAuth { source }
186 }
187}
188
189impl From<AuthError> for AnytypeGrpcError {
191 fn from(source: AuthError) -> Self {
192 AnytypeGrpcError::Auth { source }
193 }
194}
195
196impl From<ConfigError> for AnytypeGrpcError {
197 fn from(source: ConfigError) -> Self {
198 AnytypeGrpcError::Config { source }
199 }
200}
201
202impl From<ViewError> for AnytypeGrpcError {
203 fn from(source: ViewError) -> Self {
204 AnytypeGrpcError::View { source }
205 }
206}
207
208impl From<BackupError> for AnytypeGrpcError {
209 fn from(source: BackupError) -> Self {
210 AnytypeGrpcError::Backup { source }
211 }
212}
213
214impl From<tonic::transport::Error> for AnytypeGrpcError {
215 fn from(source: tonic::transport::Error) -> Self {
216 AnytypeGrpcError::Transport { source }
217 }
218}