Skip to content

Commit

Permalink
Less unwraps if CodeSpan fails
Browse files Browse the repository at this point in the history
  • Loading branch information
edomora97 committed Mar 12, 2022
1 parent c384346 commit b54e93d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
16 changes: 7 additions & 9 deletions task-maker-format/src/ioi/format/italian_yaml/cases_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,13 @@ where
description,
max_score: score,
testcases: HashMap::new(),
span: Some(
CodeSpan::from_str(
&self.file_path,
&self.file_content,
span.start(),
span.end() - span.start(),
)
.expect("Failed to extract span of subtask"),
),
span: CodeSpan::from_str(
&self.file_path,
&self.file_content,
span.start(),
span.end() - span.start(),
)
.ok(),
}));
self.subtask_id += 1;
Ok(())
Expand Down
16 changes: 7 additions & 9 deletions task-maker-format/src/ioi/format/italian_yaml/gen_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ where
description: None,
max_score: score.parse::<f64>().context("Invalid subtask score")?,
testcases: HashMap::new(),
span: Some(
CodeSpan::from_str(
path,
&content,
span.start(),
span.end() - span.start(),
)
.expect("Failed to get span of subtask"),
),
span: CodeSpan::from_str(
path,
&content,
span.start(),
span.end() - span.start(),
)
.ok(),
}));
subtask_id += 1;
}
Expand Down
19 changes: 9 additions & 10 deletions task-maker-format/src/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,15 @@ fn extract_check_list<P: AsRef<Path>>(
// file_offset includes the current line length.
let offset = file_offset - 1 - line.len() + found.start();
let len = found.end() - found.start();
let span = CodeSpan::from_str(path, &content, offset, len)
.expect("Bug generating code span for solution check");
let _ = eval.add_diagnostic(
Diagnostic::error(format!(
"In '{}' the check '{}' is not valid",
path.display(),
line
))
.with_code_span(span),
);
let mut diagnostic = Diagnostic::error(format!(
"In '{}' the check '{}' is not valid",
path.display(),
line
));
if let Ok(span) = CodeSpan::from_str(path, &content, offset, len) {
diagnostic = diagnostic.with_code_span(span);
}
let _ = eval.add_diagnostic(diagnostic);
}
}
Ok(checks)
Expand Down

0 comments on commit b54e93d

Please sign in to comment.