Skip to content

Commit

Permalink
Merge pull request #712 from vlovgr/config-exception-indent-messages
Browse files Browse the repository at this point in the history
Change ConfigException to indent messages after line breaks
  • Loading branch information
vlovgr authored Oct 23, 2023
2 parents a0c1b81 + 819124d commit 2bce44b
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 2bce44b

Please sign in to comment.