Skip to content

Commit cf87092

Browse files
dwijnandKordyjan
authored andcommitted
report: Add a Y-flag to disable enriched error messages
[Cherry-picked e6fe320]
1 parent 58ec964 commit cf87092

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ private sealed trait YSettings:
392392
val YshowVarBounds: Setting[Boolean] = BooleanSetting("-Yshow-var-bounds", "Print type variables with their bounds.")
393393

394394
val YnoDecodeStacktraces: Setting[Boolean] = BooleanSetting("-Yno-decode-stacktraces", "Show raw StackOverflow stacktraces, instead of decoding them into triggering operations.")
395+
val YnoEnrichErrorMessages: Setting[Boolean] = BooleanSetting("-Yno-enrich-error-messages", "Show raw error messages, instead of enriching them with contextual information.")
395396

396397
val Yinstrument: Setting[Boolean] = BooleanSetting("-Yinstrument", "Add instrumentation code that counts allocations and closure creations.")
397398
val YinstrumentDefs: Setting[Boolean] = BooleanSetting("-Yinstrument-defs", "Add instrumentation code that counts method calls; needs -Yinstrument to be set, too.")

compiler/src/dotty/tools/dotc/report.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ object report:
132132
private object messageRendering extends MessageRendering
133133

134134
// Should only be called from Run#enrichErrorMessage.
135-
def enrichErrorMessage(errorMessage: String)(using Context): String = try {
135+
def enrichErrorMessage(errorMessage: String)(using Context): String =
136+
if ctx.settings.YnoEnrichErrorMessages.value then errorMessage
137+
else try enrichErrorMessage1(errorMessage)
138+
catch case _: Throwable => errorMessage // don't introduce new errors trying to report errors, so swallow exceptions
139+
140+
private def enrichErrorMessage1(errorMessage: String)(using Context): String = {
141+
import untpd.*, config.Settings.*
136142
def formatExplain(pairs: List[(String, Any)]) = pairs.map((k, v) => f"$k%20s: $v").mkString("\n")
137143

138144
val settings = ctx.settings.userSetSettings(ctx.settingsState).sortBy(_.name)
@@ -155,5 +161,5 @@ object report:
155161
|
156162
|$info1
157163
|""".stripMargin
158-
} catch case _: Throwable => errorMessage // don't introduce new errors trying to report errors, so swallow exceptions
164+
}
159165
end report

0 commit comments

Comments
 (0)