Skip to content

Commit f82b08f

Browse files
committed
restore intercepting UnpickleExceptions
1 parent 9d4e3f2 commit f82b08f

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import ast.desugar
2424

2525
import parsing.JavaParsers.OutlineJavaParser
2626
import parsing.Parsers.OutlineParser
27-
import dotty.tools.tasty.TastyHeaderUnpickler
27+
import dotty.tools.tasty.{TastyHeaderUnpickler, UnpickleException}
2828

2929

3030
object SymbolLoaders {
@@ -421,14 +421,25 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
421421
def description(using Context): String = "TASTy file " + tastyFile.toString
422422

423423
override def doComplete(root: SymDenotation)(using Context): Unit =
424-
val (classRoot, moduleRoot) = rootDenots(root.asClass)
425-
val tastyBytes = tastyFile.toByteArray
426-
val unpickler = new tasty.DottyUnpickler(tastyBytes)
427-
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource))
428-
if mayLoadTreesFromTasty then
429-
classRoot.classSymbol.rootTreeOrProvider = unpickler
430-
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
431-
checkTastyUUID(tastyFile, tastyBytes)
424+
try
425+
val (classRoot, moduleRoot) = rootDenots(root.asClass)
426+
val tastyBytes = tastyFile.toByteArray
427+
val unpickler = new tasty.DottyUnpickler(tastyBytes)
428+
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource))
429+
if mayLoadTreesFromTasty then
430+
classRoot.classSymbol.rootTreeOrProvider = unpickler
431+
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
432+
checkTastyUUID(tastyFile, tastyBytes)
433+
catch case e: RuntimeException =>
434+
val message = e match
435+
case e: UnpickleException =>
436+
i"""TASTy file ${tastyFile.canonicalPath} could not be read, failing with:
437+
| ${Option(e.getMessage).getOrElse("")}"""
438+
case _ =>
439+
i"""TASTy file ${tastyFile.canonicalPath} is broken, reading aborted with ${e.getClass}
440+
| ${Option(e.getMessage).getOrElse("")}"""
441+
if (ctx.debug) e.printStackTrace()
442+
throw IOException(message)
432443

433444

434445
private def checkTastyUUID(tastyFile: AbstractFile, tastyBytes: Array[Byte])(using Context): Unit =

0 commit comments

Comments
 (0)