Skip to content

Commit fbe28d1

Browse files
MahadMuhammadCohenArthur
authored andcommitted
Refactor: Use expect for expected pass
Use `expect` instead of `unwrap` for things, we are sure cannot happen Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
1 parent 5655583 commit fbe28d1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/errors.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn load_error(text_file: &str, stderr_file: Option<&str>) -> Vec<Error> {
123123
return errors;
124124
}
125125
// TODO: improve this code incrementally
126-
let error_code_stderr = parse_error_code(stderr_file.unwrap());
126+
let error_code_stderr = parse_error_code(stderr_file.expect("stderr file is not found"));
127127

128128
for error in errors.iter_mut() {
129129
for error_code in error_code_stderr.iter() {
@@ -178,7 +178,9 @@ fn parse_error_code(stderr_content: &str) -> Vec<StderrResult> {
178178
results.push(StderrResult {
179179
error_code,
180180
error_message_detail,
181-
line_number: line_number.parse::<usize>().unwrap(),
181+
line_number: line_number
182+
.parse::<usize>()
183+
.expect("expected line number to be a valid number"),
182184
});
183185
}
184186

@@ -207,7 +209,9 @@ fn parse_expected(
207209
};
208210

209211
// Get the part of the comment after the sigil (e.g. `~^^` or ~|).
210-
let whole_match = captures.get(0).unwrap();
212+
let whole_match = captures
213+
.get(0)
214+
.expect("Failed to parse comments like \"//~\" \"//~^\" \"//~^^^^^\" ");
211215
let (_, mut msg) = line.split_at(whole_match.end());
212216

213217
let first_word = msg

0 commit comments

Comments
 (0)