From 1667244785d0fe1553dc1f3dac307bf0ebed9784 Mon Sep 17 00:00:00 2001 From: Lucian Boaca Date: Tue, 28 Oct 2025 10:59:56 +0200 Subject: [PATCH] Improve error messaging on missing configurations 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. --- .../dfx/memory/ResourceConfigTable.kt | 9 ++++++- .../memory/ResourceMemoryEvaluatorTest.java | 18 ++++++++++++++ .../MissingConfigurationDeclaration.xml | 24 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 play-validations/memory-footprint/src/test/resources/MissingConfigurationDeclaration.xml diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceConfigTable.kt b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceConfigTable.kt index 0cc9687..821c0d7 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceConfigTable.kt +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceConfigTable.kt @@ -142,7 +142,14 @@ internal class ResourceConfigTable( // in this object's resourceNameToKeys, replace each reference to a user config key with the // top level user config definition, which contains all allowed values val resourceNameToTopLevelKeys = resourceNameToKeys.entries().asSequence() - .map { it.key!! to userConfigKeys[it.value.keyId]!! } + .map { + val configurationId = it.value.keyId!! + if (userConfigKeys.containsKey(configurationId)) { + it.key!! to userConfigKeys[configurationId]!! + } else { + throw TestFailedException("Configuration $configurationId is not declared in UserConfigurations.") + } + } .toMultimap() return ResourceConfigTable(resourceNameToTopLevelKeys) diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluatorTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluatorTest.java index a4037c4..1708fb6 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluatorTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluatorTest.java @@ -1118,6 +1118,24 @@ public void evaluateWatchFaceForLayout_failsOnMissingResource() throws Exception } } + @Test + public void evaluateWatchFaceForLayout_failsOnMissingConfigurationDeclaration() + throws Exception { + try (InputStream is = + getClass().getResourceAsStream("/MissingConfigurationDeclaration.xml")) { + Document document = + DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is); + + assertThrows( + TestFailedException.class, + () -> + evaluateWatchFaceForLayout( + Collections.emptyMap(), + document, + getTestEvaluationSettings())); + } + } + @Test public void evaluateWatchFaceForLayout_greedyEvaluationCountsTTFs() throws Exception { // arrange diff --git a/play-validations/memory-footprint/src/test/resources/MissingConfigurationDeclaration.xml b/play-validations/memory-footprint/src/test/resources/MissingConfigurationDeclaration.xml new file mode 100644 index 0000000..6b3d52f --- /dev/null +++ b/play-validations/memory-footprint/src/test/resources/MissingConfigurationDeclaration.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + +