Skip to content

Commit

Permalink
Refactor: Use expect for expected pass
Browse files Browse the repository at this point in the history
Use `expect` instead of `unwrap` for things, we are sure cannot happen

Signed-off-by: Muhammad Mahad <[email protected]>
  • Loading branch information
MahadMuhammad authored and CohenArthur committed Aug 19, 2024
1 parent 5655583 commit fbe28d1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub fn load_error(text_file: &str, stderr_file: Option<&str>) -> Vec<Error> {
return errors;
}
// TODO: improve this code incrementally
let error_code_stderr = parse_error_code(stderr_file.unwrap());
let error_code_stderr = parse_error_code(stderr_file.expect("stderr file is not found"));

for error in errors.iter_mut() {
for error_code in error_code_stderr.iter() {
Expand Down Expand Up @@ -178,7 +178,9 @@ fn parse_error_code(stderr_content: &str) -> Vec<StderrResult> {
results.push(StderrResult {
error_code,
error_message_detail,
line_number: line_number.parse::<usize>().unwrap(),
line_number: line_number
.parse::<usize>()
.expect("expected line number to be a valid number"),
});
}

Expand Down Expand Up @@ -207,7 +209,9 @@ fn parse_expected(
};

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

let first_word = msg
Expand Down

0 comments on commit fbe28d1

Please sign in to comment.