Skip to content

Commit 2bb73c3

Browse files
committed
Merge pull request #975 from smarter/fix/logging
Better logging, especially of exceptions
2 parents ec2d0e4 + d4e42ea commit 2bb73c3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/dotty/tools/dotc/Driver.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ abstract class Driver extends DotClass {
5050
process(args, initCtx)
5151
}
5252

53-
def main(args: Array[String]): Unit =
53+
def main(args: Array[String]): Unit = {
54+
// Preload scala.util.control.NonFatal. Otherwise, when trying to catch a StackOverflowError,
55+
// we may try to load it but fail with another StackOverflowError and lose the original exception,
56+
// see <https://groups.google.com/forum/#!topic/scala-user/kte6nak-zPM>.
57+
val _ = NonFatal
5458
sys.exit(if (process(args).hasErrors) 1 else 0)
59+
}
5560
}
5661

5762
class FatalError(msg: String) extends Exception

src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ trait Reporting { this: Context =>
152152
case _ => String.valueOf(res)
153153
}
154154
if (printer eq config.Printers.noPrinter) op
155-
else traceIndented[T](s"==> $question?", (res: Any) => s"<== $question = ${resStr(res)}")(op)
155+
else {
156+
// Avoid evaluating question multiple time, since each evaluation
157+
// may cause some extra logging output.
158+
val q: String = question
159+
traceIndented[T](s"==> $q?", (res: Any) => s"<== $q = ${resStr(res)}")(op)
160+
}
156161
}
157162

158163
def traceIndented[T](leading: => String, trailing: Any => String)(op: => T): T =

0 commit comments

Comments
 (0)