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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
use std::{
io,
path::{Path, PathBuf},
process::ExitStatus,
};
use guppy::errors::Error as GuppyError;
use guppy::graph::PackageLink;
use thiserror::Error;
use toml_edit::TomlError as TomlEditError;
use url::ParseError;
use super::DependencyType;
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
WorkspaceError(WorkspaceError),
#[error("Workspace has at least one cycle that includes as least {crate1} and {crate2}")]
WorkspaceCycles {
crate1: String,
crate2: String,
},
#[error("Unable to write to the output")]
OutputError(#[source] io::Error),
#[error("Conditions for a release are not satisfied: {reason}")]
VerifyError {
reason: String,
},
#[error("{typ} of {from} on {to} prevents publication of {from}")]
BadDependancy {
from: String,
to: String,
typ: DependencyType,
},
#[error("Unable to read file {}", path.display())]
FileReadError {
#[source]
inner: io::Error,
path: PathBuf,
},
#[error("Unable to write file {}", path.display())]
FileWriteError {
#[source]
inner: io::Error,
path: PathBuf,
},
#[error(transparent)]
TomlError(TomlError),
#[error("Unexpected contents of {manifest_path}")]
CargoTomlError {
#[source]
inner: CargoTomlError,
manifest_path: PathBuf,
},
#[error("Unable to run \"cargo publish\" for {manifest_path}")]
CargoPublish {
#[source]
inner: io::Error,
manifest_path: PathBuf,
},
#[error("\"cargo publish\" exited with a failure for {manifest_path}: {status}")]
CargoPublishStatus {
status: ExitStatus,
manifest_path: PathBuf,
},
#[error(transparent)]
UrlError(UrlError),
#[error(transparent)]
WriteReleaseError(WriteReleaseError),
}
pub type Result<T> = std::result::Result<T, anyhow::Error>;
#[derive(Debug, Error)]
#[error("Unable to parse the workspace structure starting at {manifest_path}")]
pub struct WorkspaceError {
#[source]
metadata_error: GuppyError,
manifest_path: PathBuf,
}
#[derive(Debug, Error)]
#[error("Unable to parse {} as a TOML file", path.display())]
pub struct TomlError {
#[source]
inner: TomlEditError,
path: PathBuf,
}
#[derive(Debug, Error)]
pub enum CargoTomlError {
#[error("Unable to locate expected table {table_name}")]
NoTable {
table_name: String,
},
#[error("Unable to located expected value {value_name}")]
NoValue {
value_name: String,
},
#[error("Unable to set the version for {name} to {version}")]
SetVersion {
name: String,
version: String,
},
}
#[derive(Debug, Error)]
#[error("Unable to parse url for displaying release record.")]
pub struct UrlError {
#[source]
inner: ParseError,
}
#[derive(Debug, Error)]
#[error("Unable to write the release record for {main_crate} as JSON.")]
pub struct WriteReleaseError {
#[source]
inner: serde_json::Error,
main_crate: String,
}
impl Error {
pub(crate) fn workspace_error(metadata_error: GuppyError, manifest_path: PathBuf) -> Error {
Error::WorkspaceError(WorkspaceError {
metadata_error,
manifest_path,
})
}
pub(crate) fn output_error(inner: io::Error) -> Error {
Error::OutputError(inner)
}
pub(crate) fn verify_error(reason: impl Into<String>) -> Error {
Error::VerifyError {
reason: reason.into(),
}
}
pub(crate) fn bad_dependency(link: &PackageLink, typ: DependencyType) -> Error {
Error::BadDependancy {
from: link.from().name().to_string(),
to: link.to().name().to_string(),
typ,
}
}
pub(crate) fn file_read_error(inner: io::Error, path: impl AsRef<Path>) -> Error {
Error::FileReadError {
inner,
path: path.as_ref().to_owned(),
}
}
pub(crate) fn file_write_error(inner: io::Error, path: impl AsRef<Path>) -> Error {
Error::FileWriteError {
inner,
path: path.as_ref().to_owned(),
}
}
pub(crate) fn toml_error(inner: TomlEditError, path: impl AsRef<Path>) -> Error {
Error::TomlError(TomlError {
inner,
path: path.as_ref().to_owned(),
})
}
pub(crate) fn cargo_publish(inner: io::Error, manifest_path: &Path) -> Error {
Error::CargoPublish {
inner,
manifest_path: manifest_path.to_owned(),
}
}
pub(crate) fn cargo_publish_status(status: ExitStatus, manifest_path: &Path) -> Error {
Error::CargoPublishStatus {
status,
manifest_path: manifest_path.to_owned(),
}
}
pub(crate) fn url_parse_error(inner: ParseError) -> Error {
Error::UrlError(UrlError { inner })
}
pub(crate) fn write_release_error(inner: serde_json::Error, main_crate: &str) -> Error {
Error::WriteReleaseError(WriteReleaseError {
inner,
main_crate: main_crate.to_owned(),
})
}
}
impl CargoTomlError {
pub(crate) fn no_table(table: &str) -> Self {
Self::NoTable {
table_name: table.to_owned(),
}
}
pub(crate) fn no_value(value: &str) -> Self {
Self::NoValue {
value_name: value.to_owned(),
}
}
pub(crate) fn set_version(name: &str, version: &str) -> Self {
Self::SetVersion {
name: name.to_owned(),
version: version.to_owned(),
}
}
pub(crate) fn into_error(self, path: impl AsRef<Path>) -> Error {
Error::CargoTomlError {
inner: self,
manifest_path: path.as_ref().to_owned(),
}
}
}