Align handling of configuration error with other plugins
Common approach is either re-throw it or let it be handled by caller.
This patch resolves to later as it produces readable exceptions e.g.:
2017-11-02 12:18:08,407|DEBUG|ReceiveCommits-1|EventUtil | Error in event listener
com.google.gerrit.server.events.StreamEventsApiListener for event
com.google.gerrit.server.extensions.events.GitReferenceUpdated java.lang.IllegalStateException:
Testing how exceptions are being handled
at com.googlesource.gerrit.plugins.webhooks.Configuration.<init>(Configuration.java:41)
at com.googlesource.gerrit.plugins.webhooks.Configuration$$FastClassByGuice$$a80ded4a.newInstance(<generated>)
at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:111)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
at ...
Change-Id: If11ec445c02ce43750b089baa6bb2998627573cd
Signed-off-by: Jacek Centkowski <jcentkowski@collab.net>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java
index 42e5607..d093eeb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Configuration.java
@@ -14,9 +14,6 @@
package com.googlesource.gerrit.plugins.webhooks;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.server.config.PluginConfig;
import com.google.gerrit.server.config.PluginConfigFactory;
@@ -25,8 +22,6 @@
@Singleton
public class Configuration {
- private static final Logger log = LoggerFactory.getLogger(Configuration.class);
-
private static final int DEFAULT_TIMEOUT_MS = 5000;
private static final int DEFAULT_MAX_TRIES = 5;
private static final int DEFAULT_RETRY_INTERVAL = 1000;
@@ -44,35 +39,12 @@
protected Configuration(PluginConfigFactory config,
@PluginName String pluginName) {
PluginConfig cfg = config.getFromGerritConfig(pluginName, true);
- connectionTimeout = getInt(cfg, RemoteConfig.CONNECTION_TIMEOUT, DEFAULT_TIMEOUT_MS);
- socketTimeout = getInt(cfg, RemoteConfig.SOCKET_TIMEOUT, DEFAULT_TIMEOUT_MS);
- maxTries = getInt(cfg, RemoteConfig.MAX_TRIES, DEFAULT_MAX_TRIES);
- retryInterval = getInt(cfg, RemoteConfig.RETRY_INTERVAL, DEFAULT_RETRY_INTERVAL);
- threadPoolSize = getInt(cfg, "threadPoolSize", DEFAULT_THREAD_POOL_SIZE);
- sslVerify = getBoolean(cfg, RemoteConfig.SSL_VERIFY, DEFAULT_SSL_VERIFY);
- }
-
- protected boolean getBoolean(PluginConfig cfg, String name, boolean defaultValue) {
- try {
- return cfg.getBoolean(name, defaultValue);
- } catch (IllegalArgumentException e) {
- logError(name, "boolean", defaultValue, e);
- return defaultValue;
- }
- }
-
- protected int getInt(PluginConfig cfg, String name, int defaultValue) {
- try {
- return cfg.getInt(name, defaultValue);
- } catch (IllegalArgumentException e) {
- logError(name, "integer", defaultValue, e);
- return defaultValue;
- }
- }
-
- protected void logError(String name, String type, Object defaultValue, Exception e) {
- log.error("invalid value for{}; using default value {}", name, defaultValue);
- log.debug("Failed retrieve {} value: {}", type, e.getMessage(), e);
+ connectionTimeout = cfg.getInt(RemoteConfig.CONNECTION_TIMEOUT, DEFAULT_TIMEOUT_MS);
+ socketTimeout = cfg.getInt(RemoteConfig.SOCKET_TIMEOUT, DEFAULT_TIMEOUT_MS);
+ maxTries = cfg.getInt(RemoteConfig.MAX_TRIES, DEFAULT_MAX_TRIES);
+ retryInterval = cfg.getInt(RemoteConfig.RETRY_INTERVAL, DEFAULT_RETRY_INTERVAL);
+ threadPoolSize = cfg.getInt("threadPoolSize", DEFAULT_THREAD_POOL_SIZE);
+ sslVerify = cfg.getBoolean(RemoteConfig.SSL_VERIFY, DEFAULT_SSL_VERIFY);
}
public int getConnectionTimeout() {