Skip to content

Commit 83892e4

Browse files
committed
REPL format stack trace prefix of exception
1 parent 969d97c commit 83892e4

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

compiler/src/dotty/tools/repl/Rendering.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dotc.core.Denotations.Denotation
1111
import dotc.core.Flags
1212
import dotc.core.Flags._
1313
import dotc.core.Symbols.{Symbol, defn}
14-
import dotc.core.StdNames.str
14+
import dotc.core.StdNames.{nme, str}
1515
import dotc.core.NameOps._
1616
import dotc.printing.ReplPrinter
1717
import dotc.reporting.{MessageRendering, Message, Diagnostic}
@@ -120,20 +120,22 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
120120
if (d.symbol.is(Flags.Lazy)) Some(infoDiagnostic(dcl, d))
121121
else valueOf(d.symbol).map(value => infoDiagnostic(s"$dcl = $value", d))
122122
}
123-
catch { case ex: InvocationTargetException => Some(infoDiagnostic(renderError(ex), d)) }
123+
catch { case ex: InvocationTargetException => Some(infoDiagnostic(renderError(ex, d), d)) }
124124
}
125125

126-
/** Render the stack trace of the underlying exception */
127-
private def renderError(ex: InvocationTargetException): String = {
128-
val cause = ex.getCause match {
126+
/** Render the stack trace of the underlying exception. */
127+
private def renderError(ite: InvocationTargetException, d: Denotation)(using Context): String =
128+
import dotty.tools.dotc.util.StackTraceOps._
129+
val cause = ite.getCause match {
129130
case ex: ExceptionInInitializerError => ex.getCause
130131
case ex => ex
131132
}
132-
val sw = new StringWriter()
133-
val pw = new PrintWriter(sw)
134-
cause.printStackTrace(pw)
135-
sw.toString
136-
}
133+
def isWrapperCode(ste: StackTraceElement) =
134+
ste.getClassName == d.symbol.owner.name.show
135+
&& (ste.getMethodName == nme.STATIC_CONSTRUCTOR.show || ste.getMethodName == nme.CONSTRUCTOR.show)
136+
137+
cause.formatStackTracePrefix(!isWrapperCode(_))
138+
end renderError
137139

138140
private def infoDiagnostic(msg: String, d: Denotation)(using Context): Diagnostic =
139141
new Diagnostic.Info(msg, d.symbol.sourcePos)

0 commit comments

Comments
 (0)