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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use std::io;
use std::path::PathBuf;
macro_rules! impl_err_from {
($err:ident :: $type:ty > $variant:ident) => {
impl From<$type> for $err {
fn from(s: $type) -> Self {
$err::$variant(s)
}
}
};
}
pub type PaperClipResult<T> = Result<T, PaperClipError>;
#[derive(Debug, Fail)]
pub enum PaperClipError {
#[fail(
display = "Invalid $ref URI: {}. Only relative URIs for definitions are supported right now.",
_0
)]
InvalidRefURI(String),
#[fail(display = "Mising item schema for array: {:?}", _0)]
MissingArrayItem(Option<String>),
#[fail(display = "Invalid name for definition")]
InvalidDefinitionName,
#[fail(display = "Invalid path for definition: {:?}", _0)]
InvalidDefinitionPath(PathBuf),
#[fail(display = "Definition missing: {}", _0)]
MissingDefinition(String),
#[fail(
display = "Parameter {:?} in path {:?} defines a new schema, which is unsupported at this point.",
_0, _1
)]
UnsupportedParameterDefinition(String, String),
#[fail(
display = "Parameter {:?} in path {:?} is a body but the schema is missing",
_0, _1
)]
MissingSchemaForBodyParameter(String, String),
#[fail(display = "Parameter {:?} in path {:?} must have a type", _0, _1)]
MissingParameterType(String, String),
#[fail(
display = "Parameter {:?} in path {:?} doesn't have a known type",
_0, _1
)]
UnknownParameterType(String, String),
#[fail(display = "I/O error: {}", _0)]
Io(io::Error),
#[fail(display = "JSON error: {}", _0)]
Json(serde_json::Error),
#[fail(display = "YAML error: {}", _0)]
Yaml(serde_yaml::Error),
#[cfg(feature = "codegen-fmt")]
#[fail(display = "Rustfmt formatting error: {}", _0)]
RustFmt(rustfmt_nightly::ErrorKind),
}
impl_err_from!(PaperClipError::io::Error > Io);
impl_err_from!(PaperClipError::serde_json::Error > Json);
impl_err_from!(PaperClipError::serde_yaml::Error > Yaml);
#[cfg(feature = "codegen-fmt")]
impl_err_from!(PaperClipError::rustfmt_nightly::ErrorKind > RustFmt);