Skip to content

Replace usages of fatalError that are recoverable by non-fatal error propagation constructs #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 5, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ struct SyntaxHighlightingTokenParser {
}
}

extension Range where Bound == Position {
extension Range<Position> {
/// Splits a potentially multi-line range to multiple single-line ranges.
func splitToSingleLineRanges(in snapshot: DocumentSnapshot) -> [Self] {
if isEmpty {
Expand All @@ -220,7 +220,8 @@ extension Range where Bound == Position {
guard let startIndex = snapshot.index(of: lowerBound),
let endIndex = snapshot.index(of: upperBound)
else {
fatalError("Range \(self) reaches outside of the document")
logger.fault("Range \(self) reaches outside of the document")
return [self]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just bound the ends to the document range?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This made me re-think recovery inside position conversions altogether and I think positions conversions should never fail and always return the closest valid position, which also simplifies all client code. I’ll create a separate PR for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here we go: #1168

}

let text = snapshot.text[startIndex..<endIndex]
Expand Down