@@ -8,6 +8,7 @@ import dotty.tools.dotc.quoted.QuotesCache
88import dotty .tools .io .{AbstractFile , Directory , PlainDirectory , VirtualDirectory }
99import dotty .tools .repl .AbstractFileClassLoader
1010import dotty .tools .dotc .reporting ._
11+ import dotty .tools .dotc .config .Settings .Setting .value
1112import dotty .tools .dotc .util .ClasspathFromClassloader
1213import scala .quoted ._
1314import scala .quoted .staging .Compiler
@@ -40,7 +41,20 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
4041 setCompilerSettings(ctx1.fresh.setSetting(ctx1.settings.outputDir, outDir), settings)
4142 }
4243
43- new QuoteCompiler ().newRun(ctx).compileExpr(exprBuilder) match
44+ val compiledExpr =
45+ try
46+ new QuoteCompiler ().newRun(ctx).compileExpr(exprBuilder)
47+ catch case ex : dotty.tools.FatalError =>
48+ val enrichedMessage =
49+ s """ An unhandled exception was thrown in the staging compiler.
50+ |This might be caused by using an incorrect classloader
51+ |when creating the `staging.Compiler` instance with `staging.Compiler.make`.
52+ |For details, please refer to the documentation.
53+ |For non-enriched exceptions, compile with -Yno-enrich-error-messages. """ .stripMargin
54+ if ctx.settings.YnoEnrichErrorMessages .value(using ctx) then throw ex
55+ else throw new Exception (enrichedMessage, ex)
56+
57+ compiledExpr match
4458 case Right (value) =>
4559 value.asInstanceOf [T ]
4660
@@ -67,7 +81,6 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
6781
6882 case _ => throw ex
6983 end match
70-
7184 end run
7285
7386 override def initCtx : Context =
0 commit comments