@@ -8,6 +8,7 @@ import dotty.tools.dotc.quoted.QuotesCache
8
8
import dotty .tools .io .{AbstractFile , Directory , PlainDirectory , VirtualDirectory }
9
9
import dotty .tools .repl .AbstractFileClassLoader
10
10
import dotty .tools .dotc .reporting ._
11
+ import dotty .tools .dotc .config .Settings .Setting .value
11
12
import dotty .tools .dotc .util .ClasspathFromClassloader
12
13
import scala .quoted ._
13
14
import scala .quoted .staging .Compiler
@@ -40,7 +41,20 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
40
41
setCompilerSettings(ctx1.fresh.setSetting(ctx1.settings.outputDir, outDir), settings)
41
42
}
42
43
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
44
58
case Right (value) =>
45
59
value.asInstanceOf [T ]
46
60
@@ -59,14 +73,13 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
59
73
case _ : java.lang.NoClassDefFoundError =>
60
74
throw new Exception (
61
75
s """ `scala.quoted.staging.run` failed to load a class.
62
- |The classloader used for the `staging.Compiler` instance might not be the correct one.
63
- |Make sure that this classloader is the one that loaded the missing class.
64
- |Note that the classloader that loads the standard library might not be the same as
65
- |the one that loaded the application classes. """ .stripMargin,
76
+ |The classloader used for the `staging.Compiler` instance might not be the correct one.
77
+ |Make sure that this classloader is the one that loaded the missing class.
78
+ |Note that the classloader that loads the standard library might not be the same as
79
+ |the one that loaded the application classes. """ .stripMargin,
66
80
ex)
67
81
68
82
case _ => throw ex
69
- end match
70
83
71
84
end run
72
85
0 commit comments