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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use std::fmt;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[derive(Debug, Error)]
pub enum Error {
#[error("invalid url for {expected}: {url}")]
InvalidUrl {
url: String,
expected: ExpectedType,
},
#[error("invalid crumbfield '{field_name}', expected 'Jenkins-Crumb'")]
InvalidCrumbFieldName {
field_name: String,
},
#[error("illegal argument: '{message}'")]
IllegalArgument {
message: String,
},
#[error("illegal state: '{message}'")]
IllegalState {
message: String,
},
#[error("can't build a job remotely with parameters")]
UnsupportedBuildConfiguration,
#[error("can't do '{action}' on a {object_type} of type {variant_name}")]
InvalidObjectType {
object_type: ExpectedType,
variant_name: String,
action: Action,
},
}
#[derive(Debug, Copy, Clone)]
pub enum ExpectedType {
Build,
Job,
QueueItem,
View,
ShortView,
MavenArtifactRecord,
}
impl fmt::Display for ExpectedType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ExpectedType::Build => write!(f, "Build"),
ExpectedType::Job => write!(f, "Job"),
ExpectedType::QueueItem => write!(f, "QueueItem"),
ExpectedType::View => write!(f, "View"),
ExpectedType::ShortView => write!(f, "ShortView"),
ExpectedType::MavenArtifactRecord => write!(f, "MavenArtifactRecord"),
}
}
}
#[derive(Debug, Copy, Clone)]
pub enum Action {
GetField(&'static str),
GetLinkedItem(ExpectedType),
}
impl fmt::Display for Action {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Action::GetField(field) => write!(f, "get field '{}'", field),
Action::GetLinkedItem(item) => write!(f, "get linked item '{}'", item),
}
}
}