Skip to content

Commit

Permalink
report: Add a Y-flag to disable enriched error messages
Browse files Browse the repository at this point in the history
[Cherry-picked e6fe320]
  • Loading branch information
dwijnand authored and Kordyjan committed Nov 23, 2023
1 parent de2f85a commit 30e2685
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ private sealed trait YSettings:
val YshowVarBounds: Setting[Boolean] = BooleanSetting("-Yshow-var-bounds", "Print type variables with their bounds.")

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

val Yinstrument: Setting[Boolean] = BooleanSetting("-Yinstrument", "Add instrumentation code that counts allocations and closure creations.")
val YinstrumentDefs: Setting[Boolean] = BooleanSetting("-Yinstrument-defs", "Add instrumentation code that counts method calls; needs -Yinstrument to be set, too.")
Expand Down
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ object report:
private object messageRendering extends MessageRendering

// Should only be called from Run#enrichErrorMessage.
def enrichErrorMessage(errorMessage: String)(using Context): String = try {
def enrichErrorMessage(errorMessage: String)(using Context): String =
if ctx.settings.YnoEnrichErrorMessages.value then errorMessage
else try enrichErrorMessage1(errorMessage)
catch case _: Throwable => errorMessage // don't introduce new errors trying to report errors, so swallow exceptions

private def enrichErrorMessage1(errorMessage: String)(using Context): String = {
import untpd.*, config.Settings.*
def formatExplain(pairs: List[(String, Any)]) = pairs.map((k, v) => f"$k%20s: $v").mkString("\n")

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

0 comments on commit 30e2685

Please sign in to comment.