Skip to content

Add a FailureAnalyzer for ConfigDataNotFoundException #23633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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=\
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}