Skip to content

Commit

Permalink
Avoid unsafe unwrap of line_numbers, gracefully handle non-existing m…
Browse files Browse the repository at this point in the history
…atches

  Fixes #1044.
  • Loading branch information
KtorZ committed Oct 25, 2024
1 parent 93d0191 commit 2b7ca0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Changed

- **aiken**: Rename `--filter_traces` to `--trace_filter` for more consistency with `--trace_level`. An alias for `--filter_traces` still exists for backward compatibility. @KtorZ
- **aiken-project**: Fix `aiken docs` source linking crashing when generating docs for config modules. See [#1044](https://github.com/aiken-lang/aiken/issues/1044). @KtorZ

### Removed

Expand Down
13 changes: 10 additions & 3 deletions crates/aiken-project/src/docs/source_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ impl SourceLinker {
pub fn url(&self, span: Span) -> String {
match &self.url_pattern {
Some((base, line_sep)) => {
let start_line = self.line_numbers.line_number(span.start).unwrap();
let end_line = self.line_numbers.line_number(span.end).unwrap();
format!("{base}{start_line}{line_sep}{end_line}")
match (
self.line_numbers.line_number(span.start),
self.line_numbers.line_number(span.end),
) {
(Some(start_line), Some(end_line)) => {
format!("{base}{start_line}{line_sep}{end_line}")
}
(Some(start_line), None) => format!("{base}{start_line}"),
_ => base.to_string(),
}
}
None => "".into(),
}
Expand Down

0 comments on commit 2b7ca0e

Please sign in to comment.