1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::{borrow::Cow, io};
use thiserror::Error;
pub type Result<T> = std::result::Result<T, OciSpecError>;
#[derive(Error, Debug)]
pub enum OciSpecError {
#[error("{0}")]
Other(String),
#[error("io operation failed")]
Io(#[from] io::Error),
#[error("serde failed")]
SerDe(#[from] serde_json::Error),
#[error("uninitialized field")]
Builder(#[from] derive_builder::UninitializedFieldError),
}
pub(crate) fn oci_error<'a, M>(message: M) -> OciSpecError
where
M: Into<Cow<'a, str>>,
{
let message = message.into();
match message {
Cow::Borrowed(s) => OciSpecError::Other(s.to_owned()),
Cow::Owned(s) => OciSpecError::Other(s),
}
}