This repository was archived by the owner on Dec 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy patherrors.rs
59 lines (57 loc) · 1.87 KB
/
errors.rs
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
const ERROR_PREFIX: &'static str = "CLI assertion failed";
error_chain! {
foreign_links {
Io(::std::io::Error);
Fmt(::std::fmt::Error);
}
errors {
SpawnFailed(cmd: Vec<String>) {
description("Spawn failed")
display(
"{}: (command `{}` failed to run)",
ERROR_PREFIX,
cmd.join(" "),
)
}
StatusMismatch(cmd: Vec<String>, expected: bool, out: String, err: String) {
description("Wrong status")
display(
"{}: (command `{}` expected to {})\nstatus={}\nstdout=```{}```\nstderr=```{}```",
ERROR_PREFIX,
cmd.join(" "),
expected = if *expected { "succeed" } else { "fail" },
got = if *expected { "failed" } else { "succeeded" },
out = out,
err = err,
)
}
ExitCodeMismatch(
cmd: Vec<String>,
expected: Option<i32>,
got: Option<i32>,
out: String,
err: String
) {
description("Wrong exit code")
display(
"{prefix}: (exit code of `{cmd}` expected to be `{expected:?}`)\n\
exit code=`{code:?}`\n\
stdout=```{stdout}```\n\
stderr=```{stderr}```",
prefix=ERROR_PREFIX,
cmd=cmd.join(" "),
expected=expected,
code=got,
stdout=out,
stderr=err,
)
}
OutputMismatch(cmd: Vec<String>, output_err: ::output::Error, kind: ::output::OutputKind) {
description("Output was not as expected")
display(
"{}: `{}` {:?} mismatch: {}",
ERROR_PREFIX, cmd.join(" "), kind, output_err,
)
}
}
}