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 #4837
  • Loading branch information
tgodzik committed Feb 9, 2023
1 parent 88866fb commit f47b2da
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 f47b2da

Please sign in to comment.