This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
error.rs
102 lines (94 loc) · 3.99 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
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
use anyhow::anyhow;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum Error {
// generic errors
MalformedField,
MissingSpaceAfterColon,
LeadingWhitespace,
ExtraWhitespace,
TrailingWhitespace,
UnknownPreambleField,
// missing field
MissingEipField,
MissingTitleField,
MissingAuthorField,
MissingDiscussionsToField,
MissingStatusField,
MissingCategoryField,
MissingTypeField,
// validator level errors
StartDelimiterMissing,
EndDelimiterMissing,
MalformedEipNumber,
TitleExceedsMaxLength,
MalformedDiscussionsTo,
UnknownStatus,
UnknownType,
UnknownCategory,
MalformedReviewPeriodEnd,
MalformedCreated,
MalformedUpdated,
MalformedResolution,
MissingSpaceAfterComma,
ExtraWhitespaceBeforeComma,
OutOfOrderEips,
UnmatchedEmailDelimiter,
UnmatchedHandleDelimiter,
AuthorHasEmailAndHandle,
TrailingInfoAfterEmail,
TrailingInfoAfterHandle,
}
impl Error {
pub fn from_str(s: &str) -> anyhow::Result<Self> {
match s {
"title_max_length" => Ok(Self::TitleExceedsMaxLength),
"missing_discussions_to" => Ok(Self::MissingDiscussionsToField),
_ => Err(anyhow!("unknown validator")),
}
}
pub fn human_readable(&self) -> &'static str {
match &self {
// preamble level errors
Self::MalformedField => "malformed field",
Self::MissingSpaceAfterColon => "missing a `space` between colon and value",
Self::ExtraWhitespace => "extra whitespace",
Self::TrailingWhitespace => "trailing whitespace",
Self::LeadingWhitespace => "leading whitespace",
Self::UnknownPreambleField => "unknown preamble field",
// missing required fields
Self::MissingEipField => "missing EIP field in preamble",
Self::MissingTitleField => "missing title field in preamble",
Self::MissingAuthorField => "missing author field in preamble",
Self::MissingDiscussionsToField => "missing discussions-to field in preamble",
Self::MissingStatusField => "missing status field in preamble",
Self::MissingCategoryField => "missing category field in preamble",
Self::MissingTypeField => "missing type field in preamble",
// validator level errors
Self::StartDelimiterMissing => "missing initial '---' in preamble",
Self::EndDelimiterMissing => "missing trailing '---' in preamble",
Self::MalformedEipNumber => "EIP should be an unsigned integer",
Self::TitleExceedsMaxLength => "title exceeds max length of 55 characters",
Self::MalformedDiscussionsTo => "discussions-to must be a URL",
Self::UnknownStatus => "unknown status",
Self::UnknownType => "unknown type",
Self::UnknownCategory => "unknown category",
Self::MalformedReviewPeriodEnd => "malformed review-period-end date",
Self::MalformedCreated => "malformed created date",
Self::MalformedUpdated => "malformed updated date",
Self::MalformedResolution => "resolution must be a URL",
Self::MissingSpaceAfterComma => {
"comma-separated values must have a single space following each comma"
}
Self::ExtraWhitespaceBeforeComma => {
"comma-separated values must not have spaces before a comma"
}
Self::OutOfOrderEips => "numbers must be in ascending order",
Self::UnmatchedEmailDelimiter => "unmatched email delimiter",
Self::UnmatchedHandleDelimiter => "unmatched handle delimiter",
Self::AuthorHasEmailAndHandle => "author can't include both an email and handle",
Self::TrailingInfoAfterEmail => "trailing information after email",
Self::TrailingInfoAfterHandle => "trailing information after handle",
}
}
}