Add a FailureAnalyzer for ConfigDataNotFound

Add a `FailureAnalyzer` to deal with `ConfigDataNotFoundException`.

See gh-23633
This commit is contained in:
Michal Mlak 2020-10-11 19:18:33 +01:00 committed by Phillip Webb
parent 1cf9fc107e
commit be7d697121
3 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,21 @@
package org.springframework.boot.context.config;
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
import org.springframework.boot.diagnostics.FailureAnalysis;
/**
*
* An implementation of {@link AbstractFailureAnalyzer} to analyze failures caused by
* {@link ConfigDataLocationNotFoundException}.
*
* @author Michal Mlak
*/
public class ConfigDataLocationNotFoundExceptionFailureAnalyzer
extends AbstractFailureAnalyzer<ConfigDataLocationNotFoundException> {
@Override
protected FailureAnalysis analyze(Throwable rootFailure, ConfigDataLocationNotFoundException cause) {
return new FailureAnalysis(cause.getMessage(), null, cause);
}
}

View File

@ -74,7 +74,8 @@ org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyNameFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer,\
org.springframework.boot.diagnostics.analyzer.PatternParseFailureAnalyzer,\
org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer
org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer,\
org.springframework.boot.context.config.ConfigDataLocationNotFoundExceptionFailureAnalyzer
# Failure Analysis Reporters
org.springframework.boot.diagnostics.FailureAnalysisReporter=\

View File

@ -0,0 +1,30 @@
package org.springframework.boot.context.config;
import org.junit.jupiter.api.Test;
import org.springframework.boot.diagnostics.FailureAnalysis;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
*
* Tests for {@link ConfigDataLocationNotFoundExceptionFailureAnalyzer}
*
* @author Michal Mlak
*/
class ConfigDataLocationNotFoundExceptionFailureAnalyzerTests {
private final ConfigDataLocationNotFoundExceptionFailureAnalyzer analyzer = new ConfigDataLocationNotFoundExceptionFailureAnalyzer();
@Test
void failureAnalysisForConfigDataLocationNotFound() {
ConfigDataLocation location = mock(ConfigDataLocation.class);
ConfigDataLocationNotFoundException exception = new ConfigDataLocationNotFoundException(location);
FailureAnalysis result = analyzer.analyze(exception);
assertThat(result.getDescription()).isEqualTo("Config data location '" + location + "' does not exist");
assertThat(result.getAction()).isNull();
}
}