Skip to content

Commit c39ff5b

Browse files
committed
don't print compile error stacktrace for -e flag
1 parent 7d96568 commit c39ff5b

File tree

3 files changed

+99
-8
lines changed

3 files changed

+99
-8
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import dotty.tools.io.Jar
1515
import dotty.tools.runner.ScalaClassLoader
1616
import java.nio.file.Paths
1717
import dotty.tools.dotc.config.CommandLineParser
18-
import dotty.tools.scripting.StringDriver
18+
import dotty.tools.scripting.{StringDriver, StringDriverException, ScriptingException}
1919

2020
enum ExecuteMode:
2121
case Guess
@@ -247,8 +247,7 @@ object MainGenericRunner {
247247
++ settings.scalaArgs
248248
++ List("-script", settings.targetScript)
249249
++ settings.scriptArgs
250-
scripting.Main.main(properArgs.toArray)
251-
None
250+
scripting.Main.process(properArgs.toArray)
252251

253252
case ExecuteMode.Expression =>
254253
val cp = settings.classPath match {
@@ -269,8 +268,9 @@ object MainGenericRunner {
269268
run(settings.withExecuteMode(ExecuteMode.Repl))
270269

271270
run(settings) match
272-
case e @ Some(ex) => errorFn("", e)
273-
case _ => true
271+
case Some(ex: (StringDriverException | ScriptingException)) => errorFn(ex.getMessage)
272+
case e @ Some(ex) => errorFn("", e)
273+
case _ => true
274274

275275
def errorFn(str: String, e: Option[Throwable] = None): Boolean =
276276
if (str.nonEmpty) Console.err.println(str)

compiler/src/dotty/tools/scripting/Main.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object Main:
3333
(compilerArgs, file, scriptArgs, saveJar, invokeFlag)
3434
end distinguishArgs
3535

36-
def main(args: Array[String]): Unit =
36+
def process(args: Array[String]): Option[Throwable] =
3737
val (compilerArgs, scriptFile, scriptArgs, saveJar, invokeFlag) = distinguishArgs(args)
3838
val driver = ScriptingDriver(compilerArgs, scriptFile, scriptArgs)
3939
driver.compileAndRun { (outDir:Path, classpathEntries:Seq[Path], mainClass: String) =>
@@ -43,10 +43,13 @@ object Main:
4343
// write a standalone jar to the script parent directory
4444
writeJarfile(outDir, scriptFile, scriptArgs, classpathEntries, mainClass)
4545
invokeFlag
46-
}.map {
46+
}
47+
48+
def main(args: Array[String]): Unit =
49+
process(args).map {
4750
case ScriptingException(msg) => println(msg)
4851
case ex => ex.printStackTrace
49-
}.foreach(_ => System.exit(1))
52+
}.foreach(_ => System.exit(1))
5053

5154
private def writeJarfile(outDir: Path, scriptFile: File, scriptArgs:Array[String],
5255
classpathEntries:Seq[Path], mainClassName: String): Unit =

scoverage.coverage

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Coverage data, format version: 3.0
2+
# Statement data:
3+
# - id
4+
# - source path
5+
# - package name
6+
# - class name
7+
# - class type (Class, Object or Trait)
8+
# - full class name
9+
# - method name
10+
# - start offset
11+
# - end offset
12+
# - line number
13+
# - symbol name
14+
# - tree name
15+
# - is branch
16+
# - invocations count
17+
# - is ignored
18+
# - description (can be multi-line)
19+
# ' ' sign
20+
# ------------------------------------------
21+
0
22+
../dotty/src/main/scala/Macro.scala
23+
example
24+
Test$
25+
Object
26+
example.Test$
27+
x
28+
212
29+
217
30+
13
31+
x
32+
DefDef
33+
false
34+
0
35+
false
36+
37+
38+
1
39+
src/main/scala/Main.scala
40+
example
41+
Test$
42+
Object
43+
example.Test$
44+
foo
45+
52
46+
59
47+
5
48+
foo
49+
DefDef
50+
false
51+
0
52+
false
53+
def foo
54+
55+
2
56+
src/main/scala/Main.scala
57+
example
58+
Test$
59+
Object
60+
example.Test$
61+
hello
62+
99
63+
112
64+
8
65+
println
66+
Apply
67+
false
68+
0
69+
false
70+
println("JD")
71+
72+
3
73+
src/main/scala/Main.scala
74+
example
75+
Test$
76+
Object
77+
example.Test$
78+
hello
79+
75
80+
90
81+
7
82+
hello
83+
DefDef
84+
false
85+
0
86+
false
87+
@main def hello
88+

0 commit comments

Comments
 (0)