Skip to content

Commit

Permalink
Improve stopping message resolution debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ogesaku committed Apr 27, 2024
1 parent b0e831f commit 9b7d35f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}
22 changes: 22 additions & 0 deletions src/test/groovy/com/coditory/quark/i18n/MissingMessageSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {
Expand Down Expand Up @@ -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 ")
}
}

0 comments on commit 9b7d35f

Please sign in to comment.