Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit d959eb1

Browse files
committed
#388 Invalid property values are reported with a helpful message
1 parent 43faaa1 commit d959eb1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/main/java/com/marklogic/appdeployer/DefaultAppConfigFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public AppConfig newAppConfig() {
3333
for (String propertyName : propertyConsumerMap.keySet()) {
3434
String value = getProperty(propertyName);
3535
if (value != null) {
36-
propertyConsumerMap.get(propertyName).accept(appConfig, value);
36+
try {
37+
propertyConsumerMap.get(propertyName).accept(appConfig, value);
38+
} catch (Exception ex) {
39+
throw new IllegalArgumentException(
40+
format("Unable to parse value '%s' for property '%s'; cause: %s", value, propertyName, ex.getMessage()), ex);
41+
}
3742
}
3843
}
3944

src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ public void withProjectDirAndDefaultPaths() {
7272
assertEquals(projectPath + "/src/main/ml-schemas", appConfig.getSchemaPaths().get(0));
7373
}
7474

75+
@Test
76+
public void invalidPropertyValue() {
77+
sut = new DefaultAppConfigFactory(new SimplePropertySource("mlForestsPerHost", "3"));
78+
try {
79+
sut.newAppConfig();
80+
fail("The call should have failed because the property has an invalid value; it's expecting 'forestName,value'");
81+
} catch (IllegalArgumentException ex) {
82+
String message = ex.getMessage();
83+
assertTrue(
84+
"Expected the exception to identify the property name and value; message: " + message,
85+
message.startsWith("Unable to parse value '3' for property 'mlForestsPerHost'")
86+
);
87+
}
88+
}
89+
7590
@Test
7691
public void trimProperties() {
7792
sut = new DefaultAppConfigFactory(new SimplePropertySource("mlHost", " has-spaces ", "mlUsername", "has spaces"));

0 commit comments

Comments
 (0)