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("Transport error: {source}"))]
23 Transport { source: tonic::transport::Error },
24}
25
26#[derive(Debug, Snafu)]
28#[snafu(visibility(pub))]
29pub enum AuthError {
30 #[snafu(display("Transport error: {source}"))]
32 Status { source: tonic::Status },
33
34 #[snafu(display("API error ({code}): {description}"))]
36 Api { code: i32, description: String },
37
38 #[snafu(display("Create session returned empty token"))]
40 EmptyToken,
41
42 #[snafu(display("Invalid metadata value: {source}"))]
44 InvalidMetadata {
45 source: tonic::metadata::errors::InvalidMetadataValue,
46 },
47}
48
49#[derive(Debug, Snafu)]
51#[snafu(visibility(pub))]
52pub enum ConfigError {
53 #[snafu(display("I/O error: {source}"))]
55 Io { source: std::io::Error },
56
57 #[snafu(display("Parse error: {source}"))]
59 Parse { source: serde_json::Error },
60
61 #[snafu(display("HOME environment variable not set"))]
63 MissingHome,
64}
65
66#[derive(Debug, Snafu)]
68#[snafu(visibility(pub))]
69pub enum ViewError {
70 #[snafu(display("Transport error: {source}"))]
72 Rpc { source: tonic::Status },
73
74 #[snafu(display("API error ({code}): {description}"))]
76 ApiResponse { code: i32, description: String },
77
78 #[snafu(display("Object view missing in response"))]
80 MissingObjectView,
81
82 #[snafu(display("Dataview block not found for view id {view_id}"))]
84 MissingDataviewBlock { view_id: String },
85
86 #[snafu(display("View id {view_id} not found"))]
88 MissingView { view_id: String },
89
90 #[snafu(display("View id {view_id} is not a supported view (type {actual})"))]
92 NotSupportedView { view_id: String, actual: i32 },
93}
94
95impl From<tonic::Status> for AuthError {
97 fn from(source: tonic::Status) -> Self {
98 AuthError::Status { source }
99 }
100}
101
102impl From<tonic::metadata::errors::InvalidMetadataValue> for AuthError {
103 fn from(source: tonic::metadata::errors::InvalidMetadataValue) -> Self {
104 AuthError::InvalidMetadata { source }
105 }
106}
107
108impl From<std::io::Error> for ConfigError {
110 fn from(source: std::io::Error) -> Self {
111 ConfigError::Io { source }
112 }
113}
114
115impl From<serde_json::Error> for ConfigError {
116 fn from(source: serde_json::Error) -> Self {
117 ConfigError::Parse { source }
118 }
119}
120
121impl From<tonic::Status> for ViewError {
123 fn from(source: tonic::Status) -> Self {
124 ViewError::Rpc { source }
125 }
126}
127
128impl From<AuthError> for AnytypeGrpcError {
130 fn from(source: AuthError) -> Self {
131 AnytypeGrpcError::Auth { source }
132 }
133}
134
135impl From<ConfigError> for AnytypeGrpcError {
136 fn from(source: ConfigError) -> Self {
137 AnytypeGrpcError::Config { source }
138 }
139}
140
141impl From<ViewError> for AnytypeGrpcError {
142 fn from(source: ViewError) -> Self {
143 AnytypeGrpcError::View { source }
144 }
145}
146
147impl From<tonic::transport::Error> for AnytypeGrpcError {
148 fn from(source: tonic::transport::Error) -> Self {
149 AnytypeGrpcError::Transport { source }
150 }
151}