Merge pull request #12833 from saschamarkus/saschamarkus_issue_11510_rebase
Throw Exception for missing settings file
This commit is contained in:
commit
75d84631da
|
@ -1129,7 +1129,7 @@ public final class Settings implements ToXContent {
|
||||||
}
|
}
|
||||||
InputStream is = classLoader.getResourceAsStream(resourceName);
|
InputStream is = classLoader.getResourceAsStream(resourceName);
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
return this;
|
throw new SettingsException("Failed to load settings from [" + resourceName + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadFromStream(resourceName, is);
|
return loadFromStream(resourceName, is);
|
||||||
|
|
|
@ -63,4 +63,17 @@ public class YamlSettingsLoaderTests extends ESTestCase {
|
||||||
.loadFromClasspath("org/elasticsearch/common/settings/loader/indentation-with-explicit-document-start-settings.yml")
|
.loadFromClasspath("org/elasticsearch/common/settings/loader/indentation-with-explicit-document-start-settings.yml")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testYamlSettingsNoFile() throws Exception {
|
||||||
|
String invalidResourceName = "org/elasticsearch/common/settings/loader/no-test-settings.yml";
|
||||||
|
try {
|
||||||
|
Settings defaultSettings = settingsBuilder().loadFromClasspath(invalidResourceName).build();
|
||||||
|
fail("For a not exiting file an exception should be thrown.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
assertTrue(e instanceof SettingsException);
|
||||||
|
assertThat(e.getMessage(), equalTo("Failed to load settings from [" + invalidResourceName + "]"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue