Skip to content

Commit

Permalink
Change ConfigException to indent messages after line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
vlovgr committed Oct 23, 2023
1 parent 1da499b commit 819124d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ object ConfigException {
private[ciris] final val entryLeading: String =
"\n - "

private[ciris] final val entryNewLineLeading: String =
" " * (entryLeading.length - 1)

private[ciris] final val entryTrailing: String =
"."

private[ciris] final def formatMessage(message: String): String =
message.replaceAll("\n", s"\n$entryNewLineLeading")

private[ciris] final def message(error: ConfigError): String = {
val messages =
error.messages
error.messages.map(formatMessage)

val builder =
new java.lang.StringBuilder(messageLength(messages))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class ConfigExceptionSpec extends DisciplineSuite with Generators {
exception.getMessage

val messages =
exception.error.messages
exception.error.messages.map(ConfigException.formatMessage)

val withEntryTrailing =
messages
Expand Down Expand Up @@ -63,7 +63,8 @@ final class ConfigExceptionSpec extends DisciplineSuite with Generators {

property("ConfigException.messageLength") {
forAll { (exception: ConfigException) =>
val expected = ConfigException.messageLength(exception.error.messages)
val messages = exception.error.messages.map(ConfigException.formatMessage)
val expected = ConfigException.messageLength(messages)
val actual = exception.getMessage.length
actual === expected
}
Expand Down
3 changes: 2 additions & 1 deletion modules/core/shared/src/test/scala/ciris/Generators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ trait Generators extends GeneratorsRuntimePlatform {
val configErrorMessageGen: Gen[String] =
Gen.oneOf(
Gen.alphaNumStr,
Gen.alphaNumStr.map(_ ++ ConfigException.entryTrailing)
Gen.alphaNumStr.map(_ ++ ConfigException.entryTrailing),
Gen.alphaNumStr.map(s => s"$s\n$s")
)

val configErrorGen: Gen[ConfigError] =
Expand Down

0 comments on commit 819124d

Please sign in to comment.