All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalameta.invariants.InvariantFailedException.scala Maven / Gradle / Ivy

Go to download

Bag of private and public helpers used in scala.meta's APIs and implementations

There is a newer version: 4.12.2
Show newest version
package org.scalameta
package invariants

import org.scalameta.internal.ScalaCompat.EOL

class InvariantFailedException(message: String) extends Exception(message)

object InvariantFailedException {
  def raise(invariant: String, failures: List[String], debuggees: Map[String, Any]): Nothing =
    raise(invariant, null, failures, debuggees)
  def raise(
      invariant: String,
      clue: String,
      failures: List[String],
      debuggees: Map[String, Any]
  ): Nothing = {
    val clueStr = if (clue eq null) "" else s" ($clue)"
    val sb = new StringBuilder()
    sb.append(
      s"""|invariant failed$clueStr:
          |when verifying $invariant
          |found that ${failures.mkString(s"\nand also ")}
          |""".stripMargin.replace("\n", EOL)
    )
    ExceptionHelpers.formatDebuggees(sb, debuggees)
    throw new InvariantFailedException(sb.result())
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy