Skip to content

Commit

Permalink
bugfix: Catch StackOverflowException from the parser
Browse files Browse the repository at this point in the history
Previously, the exception could break anthing trying to use Trees and since it's an error in the parser we shouldn't break metals. Now, we catch the exception instead and print the code it failed on.

Related to scalameta#4837
  • Loading branch information
tgodzik committed Jan 25, 2023
1 parent 6dc5828 commit a206a70
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ final class Trees(
private def parse(
path: AbsolutePath,
dialect: Dialect,
): Option[Parsed[Tree]] = {
): Option[Parsed[Tree]] = try {
for {
text <- buffers.get(path).orElse(path.readTextOpt)
} yield {
Expand All @@ -132,6 +132,11 @@ final class Trees(
dialect(input).parse[Source]
}
}
} catch {
// if the parsers breaks we should not throw the exception further
case _: StackOverflowError =>
scribe.debug("Could not parse:\n" + path.readTextOpt.getOrElse(""))
None
}
}

Expand Down

0 comments on commit a206a70

Please sign in to comment.