1use std::sync::Arc;
2
3#[derive(Debug, Clone, thiserror::Error)]
4pub enum Error {
5 #[error("Invalid peer ID: {0}")]
6 InvalidPeerId(Arc<libp2p_identity::ParseError>),
7 #[error("Invalid ULID: {0}")]
8 InvalidUlid(#[from] ulid::DecodeError),
9 #[error("Qeury is missing")]
10 MissingQuery,
11 #[error("Invalid regex: {0}")]
12 InvalidRegex(#[from] regex::Error),
13 #[error("Response is missing")]
14 MissingResponse,
15 #[error("Event is missing")]
16 MissingEvent,
17 #[error("Invalid topic: Cannot contain '/'")]
18 InvalidTopic,
19 #[error("Invalid file hash: Should be 32 bytes")]
20 InvalidFileHash,
21 #[error("Invalid file path: Contains non-UTF-8 character")]
22 InvalidFilePath,
23 #[error("Invalid key: {0}")]
24 InvalidKey(String),
25 #[error("Invalid cid format")]
26 InvalidCidFormat,
27}
28
29impl From<libp2p_identity::ParseError> for Error {
30 fn from(err: libp2p_identity::ParseError) -> Self {
31 Self::InvalidPeerId(Arc::new(err))
32 }
33}
34
35impl From<Error> for tonic::Status {
36 fn from(err: Error) -> Self {
37 tonic::Status::invalid_argument(err.to_string())
38 }
39}
40
41pub type Result<T, E = Error> = std::result::Result<T, E>;