Skip to main content

starfield_datastore/
error.rs

1use crate::{ArtifactKey, CheckFailure};
2
3#[derive(Debug, thiserror::Error)]
4pub enum DatastoreError {
5    #[error("no credential configured for host {host}")]
6    NoCredential { host: String },
7    #[error("credential rejected by {host} (HTTP {status}){}", if *.looks_expired { "; it looks expired" } else { "" })]
8    CredentialRejected {
9        host: String,
10        status: u16,
11        looks_expired: bool,
12    },
13    #[error("content rejected for {key}: failed {}; got {}", .failure.check, .failure.got)]
14    ContentRejected {
15        key: ArtifactKey,
16        failure: CheckFailure,
17    },
18    #[error("offline, and {key} is not in the local cache")]
19    OfflineMiss { key: ArtifactKey },
20    #[error("{key} is not cached and the mirror is unreachable ({reason}); set STARFIELD_ALLOW_UPSTREAM=1 to fetch from the archive")]
21    MirrorUnreachable { key: ArtifactKey, reason: String },
22    #[error("{key} is not cached and has no sources; obtain it manually: {instructions}")]
23    ManualRequired {
24        key: ArtifactKey,
25        instructions: String,
26    },
27    #[error("all {} sources failed for {key}: {}", .attempts.len(), .attempts.join("; "))]
28    AllSourcesFailed {
29        key: ArtifactKey,
30        attempts: Vec<String>,
31    },
32    #[error("invalid artifact key: {0}")]
33    InvalidKey(String),
34    #[error("mirror error: {0}")]
35    Mirror(String),
36    #[error("configuration error: {0}")]
37    Config(String),
38    #[error("cold fill unavailable: {0}")]
39    FillUnavailable(String),
40    #[error("artifact transfer exceeds the reserved fill byte limit")]
41    TransferLimit,
42    #[error("manifest error: {0}")]
43    Manifest(String),
44    #[error(transparent)]
45    Io(#[from] std::io::Error),
46    #[error("HTTP request failed")]
47    Http(#[source] reqwest::Error),
48}
49
50impl From<reqwest::Error> for DatastoreError {
51    fn from(error: reqwest::Error) -> Self {
52        Self::Http(error.without_url())
53    }
54}
55
56pub type Result<T> = std::result::Result<T, DatastoreError>;