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:
@@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration
|
|||||||
@ConfigurationProperties(prefix = "forward")
|
@ConfigurationProperties(prefix = "forward")
|
||||||
class ForwardConfig {
|
class ForwardConfig {
|
||||||
|
|
||||||
private List<String> servers
|
private List<String> servers = new ArrayList<>()
|
||||||
|
|
||||||
List<String> getServers() {
|
List<String> getServers() {
|
||||||
return servers
|
return servers
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.config
|
package io.kamax.mxisd.config
|
||||||
|
|
||||||
|
import io.kamax.mxisd.exception.ConfigurationException
|
||||||
import org.apache.commons.lang.StringUtils
|
import org.apache.commons.lang.StringUtils
|
||||||
import org.springframework.beans.factory.InitializingBean
|
import org.springframework.beans.factory.InitializingBean
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
@@ -42,7 +43,7 @@ class KeyConfig implements InitializingBean {
|
|||||||
@Override
|
@Override
|
||||||
void afterPropertiesSet() throws Exception {
|
void afterPropertiesSet() throws Exception {
|
||||||
if (StringUtils.isBlank(getPath())) {
|
if (StringUtils.isBlank(getPath())) {
|
||||||
throw new RuntimeException("Key path must be configured!")
|
throw new ConfigurationException("key.path")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@ class RecursiveLookupBridgeConfig implements InitializingBean {
|
|||||||
private boolean enabled
|
private boolean enabled
|
||||||
private boolean recursiveOnly
|
private boolean recursiveOnly
|
||||||
private String server
|
private String server
|
||||||
private Map<String, String> mappings
|
private Map<String, String> mappings = new HashMap<>()
|
||||||
|
|
||||||
boolean getEnabled() {
|
boolean getEnabled() {
|
||||||
return enabled
|
return enabled
|
||||||
@@ -51,10 +51,13 @@ class RecursiveLookupBridgeConfig implements InitializingBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void afterPropertiesSet() throws Exception {
|
void afterPropertiesSet() throws Exception {
|
||||||
|
log.info("--- Bridge integration lookups config ---")
|
||||||
log.info("Enabled: {}", getEnabled())
|
log.info("Enabled: {}", getEnabled())
|
||||||
log.info("Recursive only: {}", getRecursiveOnly())
|
if (getEnabled()) {
|
||||||
log.info("Server: {}", getServer())
|
log.info("Recursive only: {}", getRecursiveOnly())
|
||||||
log.info("Mappings: {}", mappings.size())
|
log.info("Fallback Server: {}", getServer())
|
||||||
|
log.info("Mappings: {}", mappings.size())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.config
|
package io.kamax.mxisd.config
|
||||||
|
|
||||||
|
import io.kamax.mxisd.exception.ConfigurationException
|
||||||
import org.apache.commons.lang.StringUtils
|
import org.apache.commons.lang.StringUtils
|
||||||
import org.springframework.beans.factory.InitializingBean
|
import org.springframework.beans.factory.InitializingBean
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
@@ -42,7 +43,7 @@ class ServerConfig implements InitializingBean {
|
|||||||
@Override
|
@Override
|
||||||
void afterPropertiesSet() throws Exception {
|
void afterPropertiesSet() throws Exception {
|
||||||
if (StringUtils.isBlank(getName())) {
|
if (StringUtils.isBlank(getName())) {
|
||||||
throw new RuntimeException("Server name must be configured. Use the same realm as your Homeserver")
|
throw new ConfigurationException("server.name")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
2
src/main/resources/META-INF/spring.factories
Normal file
2
src/main/resources/META-INF/spring.factories
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
org.springframework.boot.diagnostics.FailureAnalyzer=\
|
||||||
|
io.kamax.mxisd.spring.ConfigurationFailureAnalyzer
|
Reference in New Issue
Block a user