Skip to content

Commit

Permalink
Fix ConfigException#toString
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Lövgren committed Nov 10, 2017
1 parent ed2face commit 490b2cf
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions modules/core/shared/src/main/scala/ciris/ConfigException.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,22 @@ package ciris
/**
* A `Throwable` representation of [[ConfigErrors]]. Useful in cases
* where it's desirable to have failed configuration loading halt
* program execution - typically during application startup.<br>
* <br>
* There's a quick way to convert [[ConfigErrors]] to an exception.
* {{{
* scala> ConfigErrors(ConfigError("error1")).toException
* res0: ConfigException = ConfigException(ConfigError(error1))
* }}}
* program execution - typically during application startup.
*
* @param errors the underlying [[ConfigErrors]] of the exception
*/
final class ConfigException private (val errors: ConfigErrors)
extends Throwable({
val errorCount =
if (errors.size == 1) "error"
else s"[${errors.size}] errors"

val errorMessages =
errors.toVector
.map(error => s" - ${error.message}.")
.mkString("\n", "\n", "\n")

s"configuration loading failed with the following $errorCount.\n$errorMessages"
s"configuration loading failed with the following errors.\n$errorMessages"
}) {

override def toString: String =
s"ConfigException(${errors.toVector.mkString(", ")})"
s"ciris.ConfigException: $getMessage"
}

object ConfigException {
Expand All @@ -38,13 +28,6 @@ object ConfigException {
*
* @param errors the [[ConfigErrors]] from which to create the exception
* @return a new [[ConfigException]]
* @example {{{
* scala> ConfigException(ConfigError("error1") append ConfigError("error2"))
* res0: ConfigException = ConfigException(ConfigError(error1), ConfigError(error2))
*
* scala> (ConfigError("error1") append ConfigError("error2")).toException
* res1: ConfigException = ConfigException(ConfigError(error1), ConfigError(error2))
* }}}
*/
def apply(errors: ConfigErrors): ConfigException =
new ConfigException(errors)
Expand Down

0 comments on commit 490b2cf

Please sign in to comment.