Improve startup failures user experience

- Be clear about config errors instead of difficult stack traces
- Fix default values which should not cause startup failures
This commit is contained in:
Maxime Dor
2017-09-03 23:26:22 +02:00
parent 466a3d270e
commit 954dcf3a5c
7 changed files with 39 additions and 7 deletions

View File

@@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration
@ConfigurationProperties(prefix = "forward")
class ForwardConfig {
private List<String> servers
private List<String> servers = new ArrayList<>()
List<String> getServers() {
return servers

View File

@@ -20,6 +20,7 @@
package io.kamax.mxisd.config
import io.kamax.mxisd.exception.ConfigurationException
import org.apache.commons.lang.StringUtils
import org.springframework.beans.factory.InitializingBean
import org.springframework.boot.context.properties.ConfigurationProperties
@@ -42,7 +43,7 @@ class KeyConfig implements InitializingBean {
@Override
void afterPropertiesSet() throws Exception {
if (StringUtils.isBlank(getPath())) {
throw new RuntimeException("Key path must be configured!")
throw new ConfigurationException("key.path")
}
}

View File

@@ -15,7 +15,7 @@ class RecursiveLookupBridgeConfig implements InitializingBean {
private boolean enabled
private boolean recursiveOnly
private String server
private Map<String, String> mappings
private Map<String, String> mappings = new HashMap<>()
boolean getEnabled() {
return enabled
@@ -51,10 +51,13 @@ class RecursiveLookupBridgeConfig implements InitializingBean {
@Override
void afterPropertiesSet() throws Exception {
log.info("--- Bridge integration lookups config ---")
log.info("Enabled: {}", getEnabled())
if (getEnabled()) {
log.info("Recursive only: {}", getRecursiveOnly())
log.info("Server: {}", getServer())
log.info("Fallback Server: {}", getServer())
log.info("Mappings: {}", mappings.size())
}
}
}

View File

@@ -20,6 +20,7 @@
package io.kamax.mxisd.config
import io.kamax.mxisd.exception.ConfigurationException
import org.apache.commons.lang.StringUtils
import org.springframework.beans.factory.InitializingBean
import org.springframework.boot.context.properties.ConfigurationProperties
@@ -42,7 +43,7 @@ class ServerConfig implements InitializingBean {
@Override
void afterPropertiesSet() throws Exception {
if (StringUtils.isBlank(getName())) {
throw new RuntimeException("Server name must be configured. Use the same realm as your Homeserver")
throw new ConfigurationException("server.name")
}
}

View File

@@ -0,0 +1,11 @@
package io.kamax.mxisd.exception;
public class ConfigurationException extends RuntimeException {
private String key;
public ConfigurationException(String key) {
super("Invalid or empty value for configuration key " + key);
}
}

View File

@@ -0,0 +1,14 @@
package io.kamax.mxisd.spring;
import io.kamax.mxisd.exception.ConfigurationException;
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
import org.springframework.boot.diagnostics.FailureAnalysis;
public class ConfigurationFailureAnalyzer extends AbstractFailureAnalyzer<ConfigurationException> {
@Override
protected FailureAnalysis analyze(Throwable rootFailure, ConfigurationException cause) {
return new FailureAnalysis(cause.getMessage(), "Double check the key value", cause);
}
}

View File

@@ -0,0 +1,2 @@
org.springframework.boot.diagnostics.FailureAnalyzer=\
io.kamax.mxisd.spring.ConfigurationFailureAnalyzer