Skip to content

Commit 846e03b

Browse files
committed
Return user visible error when catalog is misconfigured
When Driver::connect returns null, most likely it catalog is misconfigured and error message from the checkState was propagated to the user making looking obscure. Before: Query 20250825_145634_00011_9263i failed: Error listing schemas for catalog postgresql2: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Driver returned null connection, make sure the connection URL 'jdbc:psql://test' is valid for the driver org.postgresql.Driver@63a777ba After: Query 20250825_150832_00003_52kd7 failed: Error listing schemas for catalog postgresql: Driver returned null connection, make sure the connection URL 'jdbc:jdbc:postgresql://localhost:5432/tpch' and credentials are valid
1 parent b79b175 commit 846e03b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/TracingDataSource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import io.opentelemetry.api.OpenTelemetry;
1717
import io.opentelemetry.instrumentation.jdbc.datasource.JdbcTelemetry;
18+
import io.trino.spi.TrinoException;
1819

1920
import javax.sql.DataSource;
2021

@@ -25,7 +26,7 @@
2526
import java.util.Properties;
2627
import java.util.logging.Logger;
2728

28-
import static com.google.common.base.Preconditions.checkState;
29+
import static io.trino.plugin.jdbc.JdbcErrorCode.JDBC_ERROR;
2930
import static java.util.Objects.requireNonNull;
3031

3132
public class TracingDataSource
@@ -67,7 +68,9 @@ public Connection getConnection()
6768
throws SQLException
6869
{
6970
Connection connection = driver.connect(connectionUrl, properties);
70-
checkState(connection != null, "Driver returned null connection, make sure the connection URL '%s' is valid for the driver %s", connectionUrl, driver);
71+
if (connection == null) {
72+
throw new TrinoException(JDBC_ERROR, "Driver returned null connection, make sure the connection URL '%s' and credentials are valid".formatted(connectionUrl));
73+
}
7174
return connection;
7275
}
7376

0 commit comments

Comments
 (0)