use super::SecretKind;
use crate::types::ChannelId;
#[derive(Debug, thiserror::Error)]
#[error("{source}")]
pub struct ProcessError {
pub channel_id: Option<ChannelId>,
#[source]
pub source: crate::Error,
pub events: Vec<super::events::DeRecEvent>,
}
impl ProcessError {
pub fn as_non_ok_status(&self) -> Option<(i32, &str)> {
self.source.as_non_ok_status()
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SecretStoreError {
#[error("secret store backend error")]
Backend(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
#[error("secret store: missing {kind:?} entries for channel(s): {channel_ids:?}")]
MissingEntries {
kind: SecretKind,
channel_ids: Vec<u64>,
},
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ChannelStoreError {
#[error("channel already exists for {channel_id}")]
AlreadyExists { channel_id: u64 },
#[error("channel not found for {channel_id}")]
NotFound { channel_id: u64 },
#[error("channel store backend error")]
Backend(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum StateStoreError {
#[error("state store backend error")]
Backend(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Refusal {
TooFrequent,
SizeLimitExceeded,
Rejected,
}
impl Refusal {
pub(crate) fn status(self) -> derec_proto::StatusEnum {
match self {
Self::TooFrequent => derec_proto::StatusEnum::TooFrequent,
Self::SizeLimitExceeded => derec_proto::StatusEnum::SizeLimitExceeded,
Self::Rejected => derec_proto::StatusEnum::Rejected,
}
}
pub(crate) fn memo(self) -> &'static str {
match self {
Self::TooFrequent => "refused by the helper: too frequent",
Self::SizeLimitExceeded => "refused by the helper: size limit exceeded",
Self::Rejected => "refused by the helper",
}
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ShareStoreError {
#[error("share already exists for channel {channel_id} version {version}")]
AlreadyExists { channel_id: u64, version: u32 },
#[error("share not found for channel {channel_id} version {version}")]
NotFound { channel_id: u64, version: u32 },
#[error("share store backend error")]
Backend(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
#[error("share store refused the write: {0:?}")]
Refused(Refusal),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn refusal_maps_to_status_and_memo() {
assert_eq!(
Refusal::TooFrequent.status(),
derec_proto::StatusEnum::TooFrequent
);
assert_eq!(
Refusal::TooFrequent.memo(),
"refused by the helper: too frequent"
);
assert_eq!(
Refusal::SizeLimitExceeded.status(),
derec_proto::StatusEnum::SizeLimitExceeded
);
assert_eq!(
Refusal::SizeLimitExceeded.memo(),
"refused by the helper: size limit exceeded"
);
assert_eq!(
Refusal::Rejected.status(),
derec_proto::StatusEnum::Rejected
);
assert_eq!(Refusal::Rejected.memo(), "refused by the helper");
}
}