diff --git a/src/main/java/com/coditory/quark/i18n/I18nMissingMessageHandler.java b/src/main/java/com/coditory/quark/i18n/I18nMissingMessageHandler.java index ca3083e..84c4d22 100755 --- a/src/main/java/com/coditory/quark/i18n/I18nMissingMessageHandler.java +++ b/src/main/java/com/coditory/quark/i18n/I18nMissingMessageHandler.java @@ -74,8 +74,8 @@ final class DebugErrorThrowingI18NMissingMessageHandler implements I18nMissingMe String argsStringInParenthesis = argsString.isEmpty() ? "" : "(" + argsString.substring(1, argsString.length() - 1) + ')'; String keys = StreamSupport.stream(checked.spliterator(), false) .map(I18nKey::toShortString) - .collect(Collectors.joining("\n")); - throw new I18nMessagesException(format("Missing message %s%s\nChecked i18n keys:\n%s", key.toShortString(), argsStringInParenthesis, keys)); + .collect(Collectors.joining("\n ")); + throw new I18nMessagesException(format("Missing message %s%s. Checked keys:\n %s", key.toShortString(), argsStringInParenthesis, keys)); } @Override @@ -86,7 +86,7 @@ final class DebugErrorThrowingI18NMissingMessageHandler implements I18nMissingMe String argsStringInParenthesis = argsString.isEmpty() ? "" : "(" + argsString.substring(1, argsString.length() - 1) + ')'; String keys = StreamSupport.stream(checked.spliterator(), false) .map(I18nKey::toShortString) - .collect(Collectors.joining("\n")); - throw new I18nMessagesException(format("Missing message %s%s\nChecked i18n keys:\n%s", key.toShortString(), argsStringInParenthesis, keys)); + .collect(Collectors.joining("\n ")); + throw new I18nMessagesException(format("Missing message %s%s. Checked keys:\n %s", key.toShortString(), argsStringInParenthesis, keys)); } } \ No newline at end of file diff --git a/src/test/groovy/com/coditory/quark/i18n/MissingMessageSpec.groovy b/src/test/groovy/com/coditory/quark/i18n/MissingMessageSpec.groovy index ae35b35..cae8db2 100755 --- a/src/test/groovy/com/coditory/quark/i18n/MissingMessageSpec.groovy +++ b/src/test/groovy/com/coditory/quark/i18n/MissingMessageSpec.groovy @@ -6,6 +6,7 @@ import static com.coditory.quark.i18n.I18nMessagePackFactory.emptyMessagePack import static com.coditory.quark.i18n.Locales.EN import static com.coditory.quark.i18n.Locales.EN_US import static com.coditory.quark.i18n.Locales.PL +import static com.coditory.quark.i18n.Locales.PL_PL class MissingMessageSpec extends Specification { def "should throw error for missing message"() { @@ -61,4 +62,25 @@ class MissingMessageSpec extends Specification { then: result == "home.bye" } + + def "should throw error with debug info for missing message with indexed arguments"() { + given: + I18nMessagePack messages = I18nMessagePack.builder() + .setMissingMessageHandler(I18nMissingMessageHandler.debugErrorThrowingHandler()) + .prefixQueries("", "fallback") + .setDefaultLocale(PL_PL) + .build() + when: + messages.getMessage(EN_US, "home.xxx", 123, "xyz") + then: + I18nMessagesException e = thrown(I18nMessagesException) + e.message == "Missing message en-US:home.xxx(123, xyz). Checked keys:\n " + List.of("en-US:home.xxx", + "en:home.xxx", + "en-US:fallback.home.xxx", + "en:fallback.home.xxx", + "pl-PL:home.xxx", + "pl:home.xxx", + "pl-PL:fallback.home.xxx", + "pl:fallback.home.xxx").join("\n ") + } }