Skip to content

Commit 64da827

Browse files
authored
Improve error messaging on missing configurations (#102)
Some watch faces might be using user configuration nodes without declaring them. These are invalid watch faces, so the code was not treating this case properly and we were getting generic exceptions. This change adds a special error message when this error happens.
1 parent 57719a2 commit 64da827

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceConfigTable.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ internal class ResourceConfigTable(
142142
// in this object's resourceNameToKeys, replace each reference to a user config key with the
143143
// top level user config definition, which contains all allowed values
144144
val resourceNameToTopLevelKeys = resourceNameToKeys.entries().asSequence()
145-
.map { it.key!! to userConfigKeys[it.value.keyId]!! }
145+
.map {
146+
val configurationId = it.value.keyId!!
147+
if (userConfigKeys.containsKey(configurationId)) {
148+
it.key!! to userConfigKeys[configurationId]!!
149+
} else {
150+
throw TestFailedException("Configuration $configurationId is not declared in UserConfigurations.")
151+
}
152+
}
146153
.toMultimap()
147154

148155
return ResourceConfigTable(resourceNameToTopLevelKeys)

play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluatorTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,24 @@ public void evaluateWatchFaceForLayout_failsOnMissingResource() throws Exception
11181118
}
11191119
}
11201120

1121+
@Test
1122+
public void evaluateWatchFaceForLayout_failsOnMissingConfigurationDeclaration()
1123+
throws Exception {
1124+
try (InputStream is =
1125+
getClass().getResourceAsStream("/MissingConfigurationDeclaration.xml")) {
1126+
Document document =
1127+
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
1128+
1129+
assertThrows(
1130+
TestFailedException.class,
1131+
() ->
1132+
evaluateWatchFaceForLayout(
1133+
Collections.emptyMap(),
1134+
document,
1135+
getTestEvaluationSettings()));
1136+
}
1137+
}
1138+
11211139
@Test
11221140
public void evaluateWatchFaceForLayout_greedyEvaluationCountsTTFs() throws Exception {
11231141
// arrange
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<WatchFace width="450" height="450" clipShape="CIRCLE">
2+
<UserConfigurations>
3+
<ColorConfiguration id="themeColor">
4+
<ColorOption id="0" colors="#ffffffff #ffffffff #ffffffff" />
5+
<ColorOption id="1" colors="#ffe7e9ec #ffe7e9ec #ffe7e9ec" />
6+
</ColorConfiguration>
7+
</UserConfigurations>
8+
<Scene backgroundColor="#ff000000">
9+
<Group x="0" y="0" width="450" height="450" name="Image2_c630" alpha="255">
10+
<ListConfiguration id="c26cc07d_8aa0_47ea_8fed_db9ff00e2192">
11+
<ListOption id="0">
12+
<PartImage x="0" y="0" width="450" height="450" name="Image2_c630">
13+
<Image resource="wfs_b2_b9574894_f99b_46ed_8bac_e77c72c1543b"/>
14+
</PartImage>
15+
</ListOption>
16+
<ListOption id="1">
17+
<PartImage x="0" y="0" width="450" height="450" name="Image2_c630">
18+
<Image resource="wfs_10_9e935b0e_0763_4121_a3d6_5a6e649c1947"/>
19+
</PartImage>
20+
</ListOption>
21+
</ListConfiguration>
22+
</Group>
23+
</Scene>
24+
</WatchFace>

0 commit comments

Comments
 (0)