caretta_sync_core/
error.rs1use std::{array::TryFromSliceError, ffi::OsString};
2use tonic::Status;
3
4use crate::proto::ProtoDeserializeError;
5
6#[derive(thiserror::Error, Debug)]
7pub enum Error {
8 #[error("Base64 decode error: {0}")]
9 Base64Decode(#[from] base64::DecodeError),
10 #[error("Config error: {0}")]
11 Config(#[from] crate::config::error::ConfigError),
12 #[error("Infallible: {0}")]
13 Infallible(#[from] std::convert::Infallible),
14 #[error("IO Error: {0}")]
15 Io(#[from] std::io::Error),
16 #[error("Iroh bind error: {0}")]
17 IrohBind(#[from] iroh::endpoint::BindError),
18 #[error("mandatory config `{0}` is missing")]
19 MissingConfig(&'static str),
20 #[error("Parse OsString error: {0:?}")]
21 OsStringConvert(std::ffi::OsString),
22 #[cfg(feature = "cli")]
23 #[error("Parse args error: {0}")]
24 ParseCommand(#[from] clap::Error),
25 #[error("slice parse error: {0}")]
26 SliceTryFrom(#[from] TryFromSliceError),
27 #[error("toml deserialization error: {0}")]
28 TomlDe(#[from] toml::de::Error),
29 #[error("toml serialization error: {0}")]
30 TomlSer(#[from] toml::ser::Error),
31 #[error("protobuf serialization error: {0}")]
32 ProtoSerialize(#[from] crate::proto::ProtoSerializeError),
33 #[error("protobuf deserialization error: {0}")]
34 ProtoDeserialize(#[from] crate::proto::ProtoDeserializeError),
35 #[error("Local record error: {0}")]
36 LocalDb(#[from] sea_orm::DbErr),
37 #[error("Tripod id error: {0}")]
38 TripodId(#[from] mtid::Error),
39}
40
41impl From<std::ffi::OsString> for Error {
42 fn from(s: OsString) -> Error {
43 Self::OsStringConvert(s)
44 }
45}
46
47impl From<Error> for Status {
48 fn from(value: Error) -> Self {
49 match value {
50 Error::ProtoDeserialize(x) => match x {
51 ProtoDeserializeError::MissingField(x) => {
52 Self::invalid_argument(format!("{} is required", x))
53 }
54 _ => Status::unimplemented("Unimplemented protobuf deserialize error status"),
55 },
56 _ => Status::unimplemented("Unimplemented error status"),
57 }
58 }
59}