def issueFallbackWarning[T: c.WeakTypeTag]()

in scio-macros/src/main/scala/com/spotify/scio/coders/CoderMacros.scala [43:121]


  def issueFallbackWarning[T: c.WeakTypeTag](
    c: whitebox.Context
  )(@unused lp: c.Expr[shapeless.LowPriority]): c.Tree = {
    import c.universe._

    val show = MacroSettings.showCoderFallback(c) == FeatureFlag.Enable

    val wtt = weakTypeOf[T]
    val TypeRef(_, sym, args) = wtt: @nowarn

    val typeName = sym.name
    val params = args.headOption
      .map(_ => args.mkString("[", ",", "]"))
      .getOrElse("")
    val fullType = s"$typeName$params"

    val toReport = c.enclosingPosition.toString -> wtt.toString
    val alreadyReported = reported.contains(toReport)
    if (!alreadyReported) reported += toReport

    val shortMessage =
      s"""
      | Warning: No implicit Coder found for the following type:
      |
      |   >> $wtt
      |
      | using Kryo fallback instead.
      """

    val longMessage =
      shortMessage +
        s"""
        |
        |  Scio will use a fallback Kryo coder instead.
        |
        |  If a type is not supported, consider implementing your own implicit Coder for this type.
        |  It is recommended to declare this Coder in your class companion object:
        |
        |       object $typeName {
        |         import com.spotify.scio.coders.Coder
        |         import org.apache.beam.sdk.coders.AtomicCoder
        |
        |         implicit def coder$typeName: Coder[$fullType] =
        |           Coder.beam(new AtomicCoder[$fullType] {
        |             def decode(in: InputStream): $fullType = ???
        |             def encode(ts: $fullType, out: OutputStream): Unit = ???
        |           })
        |       }
        |
        |  If you do want to use a Kryo coder, be explicit about it:
        |
        |       implicit def coder$typeName: Coder[$fullType] = Coder.kryo[$fullType]
        |
        |  Additional info at:
        |   - https://spotify.github.io/scio/internals/Coders
        |
        """

    val fallback = q"""_root_.com.spotify.scio.coders.Coder.kryo[$wtt]"""

    (verbose, alreadyReported) match {
      case _ if BlacklistedTypes.contains(wtt.toString) =>
        val msg =
          s"Can't use a Kryo coder for $wtt. You need to explicitly set the Coder for this type"
        c.abort(c.enclosingPosition, msg)
      case _ if Warnings.contains(wtt.toString) =>
        c.echo(c.enclosingPosition, Warnings(wtt.toString))
        fallback
      case (false, false) =>
        if (show) c.echo(c.enclosingPosition, shortMessage.stripMargin)
        fallback
      case (true, false) =>
        if (show) c.echo(c.enclosingPosition, longMessage.stripMargin)
        verbose = false
        fallback
      case (_, _) =>
        fallback
    }
  }