caretta-sync/core/src/error.rs

63 lines
2.3 KiB
Rust
Raw Normal View History

2025-09-05 06:22:36 +09:00
use std::{array::TryFromSliceError, ffi::OsString};
2025-10-01 07:19:35 +09:00
use tonic::Status;
use crate::proto::ProtoDeserializeError;
2025-08-20 06:50:35 +09:00
2025-05-24 09:17:45 +09:00
#[derive(thiserror::Error, Debug)]
pub enum Error {
2025-06-01 15:18:17 +09:00
#[error("Base64 decode error: {0}")]
Base64Decode(#[from] base64::DecodeError),
2025-06-18 08:36:01 +09:00
#[error(transparent)]
CiborDeserialize(#[from] ciborium::de::Error<std::io::Error>),
#[error(transparent)]
CiborSerialize(#[from] ciborium::ser::Error<std::io::Error>),
2025-08-21 07:40:33 +09:00
#[error("Config error: {0}")]
Config(#[from] crate::config::error::ConfigError),
2025-06-01 15:18:17 +09:00
#[error("Infallible: {0}")]
Infallible(#[from] std::convert::Infallible),
2025-05-30 09:26:47 +09:00
#[error("IO Error: {0}")]
Io(#[from]std::io::Error),
2025-09-03 13:22:31 +09:00
#[error("Iroh bind error: {0}")]
IrohBind(#[from] iroh::endpoint::BindError),
2025-05-24 09:17:45 +09:00
#[error("mandatory config `{0}` is missing")]
2025-06-01 15:18:17 +09:00
MissingConfig(&'static str),
2025-08-20 06:50:35 +09:00
#[error("Parse OsString error: {0:?}")]
OsStringConvert(std::ffi::OsString),
#[cfg(feature="cli")]
2025-06-18 08:36:01 +09:00
#[error("Parse args error: {0}")]
ParseCommand(#[from] clap::Error),
2025-09-05 06:22:36 +09:00
#[error("Signature error: {0}")]
Signature(#[from] ed25519_dalek::SignatureError),
#[error("slice parse error: {0}")]
SliceTryFrom(#[from] TryFromSliceError),
2025-05-30 09:26:47 +09:00
#[error("toml deserialization error: {0}")]
TomlDe(#[from] toml::de::Error),
#[error("toml serialization error: {0}")]
2025-06-18 08:36:01 +09:00
TomlSer(#[from] toml::ser::Error),
2025-10-01 07:19:35 +09:00
#[error("protobuf serialization error: {0}")]
ProtoSerialize(#[from] crate::proto::ProtoSerializeError),
#[error("protobuf deserialization error: {0}")]
ProtoDeserialize(#[from] crate::proto::ProtoDeserializeError),
#[error("Local record error: {0}")]
LocalRecord(#[from] crate::data::local::LocalRecordError),
#[error("Tripod id error: {0}")]
TripodId(#[from] tripod_id::Error),
2025-08-20 06:50:35 +09:00
}
impl From<std::ffi::OsString> for Error {
fn from(s: OsString) -> Error {
Self::OsStringConvert(s)
}
2025-10-01 07:19:35 +09:00
}
impl From<Error> for Status {
fn from(value: Error) -> Self {
match value {
Error::ProtoDeserialize(x) => { match x {
ProtoDeserializeError::MissingField(x) => Self::invalid_argument(format!("{} is required", x)),
_ => Status::unimplemented("Unimplemented protobuf deserialize error status")
}},
_ => Status::unimplemented("Unimplemented error status")
}
}
2025-05-24 09:17:45 +09:00
}