Skip to content

Commit be7d697

Browse files
Miehauphilwebb
authored andcommitted
Add a FailureAnalyzer for ConfigDataNotFound
Add a `FailureAnalyzer` to deal with `ConfigDataNotFoundException`. See gh-23633
1 parent 1cf9fc1 commit be7d697

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.springframework.boot.context.config;
2+
3+
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
4+
import org.springframework.boot.diagnostics.FailureAnalysis;
5+
6+
/**
7+
*
8+
* An implementation of {@link AbstractFailureAnalyzer} to analyze failures caused by
9+
* {@link ConfigDataLocationNotFoundException}.
10+
*
11+
* @author Michal Mlak
12+
*/
13+
public class ConfigDataLocationNotFoundExceptionFailureAnalyzer
14+
extends AbstractFailureAnalyzer<ConfigDataLocationNotFoundException> {
15+
16+
@Override
17+
protected FailureAnalysis analyze(Throwable rootFailure, ConfigDataLocationNotFoundException cause) {
18+
return new FailureAnalysis(cause.getMessage(), null, cause);
19+
}
20+
21+
}

spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer
7474
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyNameFailureAnalyzer,\
7575
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer,\
7676
org.springframework.boot.diagnostics.analyzer.PatternParseFailureAnalyzer,\
77-
org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer
77+
org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer,\
78+
org.springframework.boot.context.config.ConfigDataLocationNotFoundExceptionFailureAnalyzer
7879

7980
# Failure Analysis Reporters
8081
org.springframework.boot.diagnostics.FailureAnalysisReporter=\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.springframework.boot.context.config;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.diagnostics.FailureAnalysis;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
import static org.mockito.Mockito.mock;
8+
9+
/**
10+
*
11+
* Tests for {@link ConfigDataLocationNotFoundExceptionFailureAnalyzer}
12+
*
13+
* @author Michal Mlak
14+
*/
15+
class ConfigDataLocationNotFoundExceptionFailureAnalyzerTests {
16+
17+
private final ConfigDataLocationNotFoundExceptionFailureAnalyzer analyzer = new ConfigDataLocationNotFoundExceptionFailureAnalyzer();
18+
19+
@Test
20+
void failureAnalysisForConfigDataLocationNotFound() {
21+
ConfigDataLocation location = mock(ConfigDataLocation.class);
22+
ConfigDataLocationNotFoundException exception = new ConfigDataLocationNotFoundException(location);
23+
24+
FailureAnalysis result = analyzer.analyze(exception);
25+
26+
assertThat(result.getDescription()).isEqualTo("Config data location '" + location + "' does not exist");
27+
assertThat(result.getAction()).isNull();
28+
}
29+
30+
}

0 commit comments

Comments
 (0)