tuwunel_service/fetcher/
error.rs1use std::fmt;
4
5use ruma::OwnedServerName;
6use tuwunel_core::{err, smallvec::SmallVec};
7
8pub(super) type Attempted = SmallVec<[OwnedServerName; 3]>;
10
11#[derive(Clone, Debug)]
16pub(super) enum Failure {
17 NotFound {
19 attempted: Attempted,
20 },
21
22 NoCandidates,
24
25 Cancelled,
27}
28
29impl fmt::Display for Failure {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 | Self::NoCandidates => write!(f, "no candidate servers available"),
33 | Self::Cancelled => write!(f, "fetch cancelled"),
34 | Self::NotFound { attempted } => {
35 write!(f, "event not found on any of {} servers", attempted.len())
36 },
37 }
38 }
39}
40
41impl From<Failure> for tuwunel_core::Error {
42 fn from(failure: Failure) -> Self { err!(Request(NotFound("{failure}"))) }
43}