Skip to content

Commit

Permalink
Merge pull request #30751 from gastaldi/improve_msg
Browse files Browse the repository at this point in the history
Improve JDBC driver error message in Agroal processor
  • Loading branch information
yrodiere authored Feb 1, 2023
2 parents f3cc60c + 8a4897e commit d7c0292
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.enterprise.inject.Default;
import javax.inject.Singleton;
Expand Down Expand Up @@ -344,14 +345,13 @@ private String resolveDriver(String dataSourceName, String dbKind,
}
}

throw new ConfigurationException("Unable to find a JDBC driver corresponding to the database kind '"
+ dbKind + "' for the "
+ (DataSourceUtil.isDefault(dataSourceName) ? "default datasource"
: "datasource '" + dataSourceName + "'")
+ ". Either provide a suitable JDBC driver extension, define the driver manually, or disable the JDBC datasource by adding "
+ (DataSourceUtil.isDefault(dataSourceName) ? "'quarkus.datasource.jdbc=false'"
: "'quarkus.datasource." + dataSourceName + ".jdbc=false'")
+ " to your configuration if you don't need it.");
throw new ConfigurationException(String.format(
"Unable to find a JDBC driver corresponding to the database kind '%s' for the %s (available: '%s'). "
+ "Check if it's a typo, otherwise provide a suitable JDBC driver extension, define the driver manually,"
+ " or disable the JDBC datasource by adding '%s=false' to your configuration if you don't need it.",
dbKind, DataSourceUtil.isDefault(dataSourceName) ? "default datasource" : "datasource '" + dataSourceName + "'",
jdbcDriverBuildItems.stream().map(JdbcDriverBuildItem::getDbKind).collect(Collectors.joining("','")),
DataSourceUtil.dataSourcePropertyKey(dataSourceName, "jdbc")));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,10 @@ public AgroalDataSource doCreateDataSource(String dataSourceName) {

DataSourceSupport.Entry matchingSupportEntry = dataSourceSupport.entries.get(dataSourceName);
if (!dataSourceJdbcRuntimeConfig.url.isPresent()) {
String errorMessage;
// we don't have any URL configuration so using a standard message
if (DataSourceUtil.isDefault(dataSourceName)) {
errorMessage = "quarkus.datasource.jdbc.url has not been defined";
} else {
errorMessage = "quarkus.datasource." + dataSourceName + ".jdbc.url has not been defined";
}
//this is not an error situation, because we want to allow the situation where a JDBC extension
//is installed but has not been configured
return new UnconfiguredDataSource(errorMessage);
return new UnconfiguredDataSource(
DataSourceUtil.dataSourcePropertyKey(dataSourceName, "jdbc.url") + " has not been defined");
}

// we first make sure that all available JDBC drivers are loaded in the current TCCL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public static boolean hasDefault(Collection<String> dataSourceNames) {
return dataSourceNames.contains(DEFAULT_DATASOURCE_NAME);
}

public static String dataSourcePropertyKey(String datasourceName, String radical) {
if (datasourceName == null || DataSourceUtil.isDefault(datasourceName)) {
return "quarkus.datasource." + radical;
} else {
return "quarkus.datasource.\"" + datasourceName + "\"." + radical;
}
}

public static List<String> dataSourcePropertyKeys(String datasourceName, String radical) {
if (datasourceName == null || DataSourceUtil.isDefault(datasourceName)) {
return List.of("quarkus.datasource." + radical);
Expand Down

0 comments on commit d7c0292

Please sign in to comment.