Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ConfigException to indent messages after line breaks #712

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading