Skip to content

Commit 9b7d35f

Browse files
committed
Improve stopping message resolution debugging
1 parent b0e831f commit 9b7d35f

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/main/java/com/coditory/quark/i18n/I18nMissingMessageHandler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ final class DebugErrorThrowingI18NMissingMessageHandler implements I18nMissingMe
7474
String argsStringInParenthesis = argsString.isEmpty() ? "" : "(" + argsString.substring(1, argsString.length() - 1) + ')';
7575
String keys = StreamSupport.stream(checked.spliterator(), false)
7676
.map(I18nKey::toShortString)
77-
.collect(Collectors.joining("\n"));
78-
throw new I18nMessagesException(format("Missing message %s%s\nChecked i18n keys:\n%s", key.toShortString(), argsStringInParenthesis, keys));
77+
.collect(Collectors.joining("\n "));
78+
throw new I18nMessagesException(format("Missing message %s%s. Checked keys:\n %s", key.toShortString(), argsStringInParenthesis, keys));
7979
}
8080

8181
@Override
@@ -86,7 +86,7 @@ final class DebugErrorThrowingI18NMissingMessageHandler implements I18nMissingMe
8686
String argsStringInParenthesis = argsString.isEmpty() ? "" : "(" + argsString.substring(1, argsString.length() - 1) + ')';
8787
String keys = StreamSupport.stream(checked.spliterator(), false)
8888
.map(I18nKey::toShortString)
89-
.collect(Collectors.joining("\n"));
90-
throw new I18nMessagesException(format("Missing message %s%s\nChecked i18n keys:\n%s", key.toShortString(), argsStringInParenthesis, keys));
89+
.collect(Collectors.joining("\n "));
90+
throw new I18nMessagesException(format("Missing message %s%s. Checked keys:\n %s", key.toShortString(), argsStringInParenthesis, keys));
9191
}
9292
}

src/test/groovy/com/coditory/quark/i18n/MissingMessageSpec.groovy

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import static com.coditory.quark.i18n.I18nMessagePackFactory.emptyMessagePack
66
import static com.coditory.quark.i18n.Locales.EN
77
import static com.coditory.quark.i18n.Locales.EN_US
88
import static com.coditory.quark.i18n.Locales.PL
9+
import static com.coditory.quark.i18n.Locales.PL_PL
910

1011
class MissingMessageSpec extends Specification {
1112
def "should throw error for missing message"() {
@@ -61,4 +62,25 @@ class MissingMessageSpec extends Specification {
6162
then:
6263
result == "home.bye"
6364
}
65+
66+
def "should throw error with debug info for missing message with indexed arguments"() {
67+
given:
68+
I18nMessagePack messages = I18nMessagePack.builder()
69+
.setMissingMessageHandler(I18nMissingMessageHandler.debugErrorThrowingHandler())
70+
.prefixQueries("", "fallback")
71+
.setDefaultLocale(PL_PL)
72+
.build()
73+
when:
74+
messages.getMessage(EN_US, "home.xxx", 123, "xyz")
75+
then:
76+
I18nMessagesException e = thrown(I18nMessagesException)
77+
e.message == "Missing message en-US:home.xxx(123, xyz). Checked keys:\n " + List.of("en-US:home.xxx",
78+
"en:home.xxx",
79+
"en-US:fallback.home.xxx",
80+
"en:fallback.home.xxx",
81+
"pl-PL:home.xxx",
82+
"pl:home.xxx",
83+
"pl-PL:fallback.home.xxx",
84+
"pl:fallback.home.xxx").join("\n ")
85+
}
6486
}

0 commit comments

Comments
 (0)