Deal with failure to load automerger config.
When we fail to load the config, immediately throw an
error instead of loading an empty config.
Change-Id: I79838b2e92f30df7bf86be2730ef3031beab4848
diff --git a/src/main/java/com/googlesource/gerrit/plugins/automerger/ConfigLoader.java b/src/main/java/com/googlesource/gerrit/plugins/automerger/ConfigLoader.java
index e74e5b2..87ff91c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/automerger/ConfigLoader.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/automerger/ConfigLoader.java
@@ -55,7 +55,7 @@
* @throws IOException if reading config_keys.yaml failed
*/
@Inject
- public ConfigLoader(GerritApi gApi) throws IOException {
+ public ConfigLoader(GerritApi gApi) throws IOException, RestApiException {
this.gApi = gApi;
String configKeysPath = "/config/config_keys.yaml";
@@ -69,12 +69,7 @@
configFilename = (String) automergerConfig.get("config_filename");
configOptionKeys = (List<String>) automergerConfig.get("config_option_keys");
- try {
- loadConfig();
- } catch (IOException | RestApiException e) {
- log.error("Config failed to sync!", e);
- config = new LoadedConfig();
- }
+ loadConfig();
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/automerger/LoadedConfig.java b/src/main/java/com/googlesource/gerrit/plugins/automerger/LoadedConfig.java
index 30691b0..058a879 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/automerger/LoadedConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/automerger/LoadedConfig.java
@@ -133,7 +133,7 @@
* @return A map of from branches to their configuration maps.
*/
public Map<String, Map> getBranches() {
- return (Map<String, Map>) config.get("branches");
+ return (Map<String, Map>) config.getOrDefault("branches", Collections.emptyMap());
}
/**