1use std::io;
2use std::path::PathBuf;
3
4use crate::Digest;
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10 #[error("{context}: {source}")]
11 Io {
12 context: String,
13 #[source]
14 source: io::Error,
15 },
16 #[error("invalid digest {0:?} (only sha256:<64 lowercase hex> is accepted)")]
17 BadDigest(String),
18 #[error("digest mismatch: expected {expected}, got {actual}")]
19 DigestMismatch { expected: Digest, actual: Digest },
20 #[error("invalid image reference {0:?}")]
21 BadReference(String),
22 #[error("layer entry {0:?} would land outside the rootfs")]
23 Escape(PathBuf),
24 #[error("blob {0} is not in the store")]
25 MissingBlob(Digest),
26 #[error("{0}")]
27 Invalid(String),
28 #[cfg(feature = "pull")]
29 #[error("registry: {0}")]
30 Http(#[from] reqwest::Error),
31}
32
33pub(crate) trait Context<T> {
35 fn ctx(self, what: impl FnOnce() -> String) -> Result<T>;
36}
37
38impl<T> Context<T> for io::Result<T> {
39 fn ctx(self, what: impl FnOnce() -> String) -> Result<T> {
40 self.map_err(|source| Error::Io {
41 context: what(),
42 source,
43 })
44 }
45}