ankurah_core/
error.rs

1use std::convert::Infallible;
2
3use ankurah_proto::{DecodeError, ID};
4use thiserror::Error;
5
6use crate::connector::SendError;
7
8#[derive(Error, Debug)]
9pub enum RetrievalError {
10    #[error("Parse error: {0}")]
11    ParseError(ankql::error::ParseError),
12    #[error("ID {0:?} not found")]
13    NotFound(ID),
14    #[error("Storage error: {0}")]
15    StorageError(Box<dyn std::error::Error + Send + Sync + 'static>),
16    #[error("Update failed: {0}")]
17    FailedUpdate(Box<dyn std::error::Error + Send + Sync + 'static>),
18    #[error("Deserialization error: {0}")]
19    DeserializationError(bincode::Error),
20    #[error("No durable peers available for fetch operation")]
21    NoDurablePeers,
22    #[error("Other error: {0}")]
23    Other(String),
24    #[error("bucket name must only contain valid characters")]
25    InvalidBucketName,
26    #[error("ankql filter: {0}")]
27    AnkqlFilter(ankql::selection::filter::Error),
28    #[error("Future join: {0}")]
29    FutureJoin(Box<dyn std::error::Error + Send + Sync + 'static>),
30    #[error("{0}")]
31    Anyhow(anyhow::Error),
32    #[error("Decode error: {0}")]
33    DecodeError(DecodeError),
34}
35
36impl RetrievalError {
37    pub fn storage(err: impl std::error::Error + Send + Sync + 'static) -> Self { RetrievalError::StorageError(Box::new(err)) }
38
39    pub fn future_join(err: impl std::error::Error + Send + Sync + 'static) -> Self { RetrievalError::FutureJoin(Box::new(err)) }
40}
41
42impl From<bincode::Error> for RetrievalError {
43    fn from(e: bincode::Error) -> Self { RetrievalError::DeserializationError(e) }
44}
45
46impl From<ankql::selection::filter::Error> for RetrievalError {
47    fn from(err: ankql::selection::filter::Error) -> Self { RetrievalError::AnkqlFilter(err) }
48}
49
50impl From<anyhow::Error> for RetrievalError {
51    fn from(err: anyhow::Error) -> Self { RetrievalError::Anyhow(err) }
52}
53
54impl From<Infallible> for RetrievalError {
55    fn from(_: Infallible) -> Self { unreachable!() }
56}
57
58#[derive(Error, Debug)]
59pub enum RequestError {
60    #[error("Peer not connected")]
61    PeerNotConnected,
62    #[error("Connection lost")]
63    ConnectionLost,
64    #[error("Send error: {0}")]
65    SendError(SendError),
66    #[error("Internal channel closed")]
67    InternalChannelClosed,
68}
69
70impl From<SendError> for RequestError {
71    fn from(err: SendError) -> Self { RequestError::SendError(err) }
72}
73
74impl From<DecodeError> for RetrievalError {
75    fn from(err: DecodeError) -> Self { RetrievalError::DecodeError(err) }
76}