-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.rs
77 lines (62 loc) · 1.63 KB
/
error.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Error representations
//!
use std::fmt::Display;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
// if the error name and description don't explain it, a one-line comment isn't going to help either
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
#[allow(clippy::large_enum_variant)] // I'm OK with errors being phat
pub enum Error {
#[error("An internal error occurred: {0} (please report a bug!)")]
InternalError(String),
#[error("{0}: {1}")]
SystemError(String, String),
#[error("failed to parse JSON for {0}: {1}")]
JsonParseError(String, String),
#[error("failed to decode log entry: {0}")]
EntryDecodingError(String),
#[error("HTTP request failed: {0}")]
RequestError(ureq::Error),
#[error("failed to serialize {0} output: {1}")]
OutputError(String, String),
#[error("failed to construct {0} URL: {1}")]
URLError(String, url::ParseError),
#[error("arithmetic operation overflowed: {0}")]
ArithmeticOverflow(String),
}
impl Error {
pub(crate) fn internal<D>(desc: D) -> Self
where
D: Display,
{
Self::InternalError(desc.to_string())
}
pub(crate) fn system<D, E>(desc: D, e: E) -> Self
where
D: Display,
E: Display,
{
Self::SystemError(desc.to_string(), e.to_string())
}
pub(crate) fn output<D, E>(desc: D, e: E) -> Self
where
D: Display,
E: Display,
{
Self::OutputError(desc.to_string(), e.to_string())
}
pub(crate) fn json_parse<C, E>(ctx: C, e: E) -> Self
where
C: Display,
E: Display,
{
Self::JsonParseError(ctx.to_string(), e.to_string())
}
pub(crate) fn arithmetic<O>(op: O) -> Self
where
O: Display,
{
Self::ArithmeticOverflow(op.to_string())
}
}