Skip to content

Commit

Permalink
Gracefully handle invalid jar files during mtags indexing.
Browse files Browse the repository at this point in the history
Previously, the indexing pipeline would crash if a `*-sources.jar` did not have valid jar contents.
  • Loading branch information
Olafur Pall Geirsson committed Dec 4, 2019
1 parent 0d1c46f commit fd4f4d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ import scala.util.control.NonFatal
import scala.util.Success
import com.google.gson.JsonPrimitive
import scala.meta.internal.worksheets.WorksheetProvider
import scala.meta.internal.worksheets.WorksheetProvider
import scala.meta.internal.decorations.PublishDecorationsParams
import scala.meta.internal.rename.RenameProvider
import ch.epfl.scala.bsp4j.CompileReport
import java.{util => ju}

class MetalsLanguageServer(
ec: ExecutionContextExecutorService,
Expand Down Expand Up @@ -1705,11 +1705,15 @@ class MetalsLanguageServer(
case None =>
// Nothing in cache, read top level symbols and store them in cache
val tempIndex = OnDemandSymbolIndex(onError = {
case e: InvalidJarException =>
scribe.warn(s"invalid jar: ${e.path}")
case NonFatal(e) =>
scribe.warn(s"Error when reading source jar [$path]", e)
scribe.warn(s"jar error: $path", e)
})
tempIndex.addSourceJar(path)
tables.jarSymbols.putTopLevels(path, tempIndex.toplevels)
if (tempIndex.toplevels.nonEmpty) {
tables.jarSymbols.putTopLevels(path, tempIndex.toplevels)
}
tempIndex.toplevels
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package scala.meta.internal.mtags

import scala.meta.io.AbsolutePath

case class InvalidJarException(path: AbsolutePath, underlying: Throwable)
extends Exception(path.toString)

0 comments on commit fd4f4d1

Please sign in to comment.