Skip to content

Commit f129738

Browse files
yahondaclaude
andcommitted
Narrow DriverManager fallback rescue to no-suitable-driver errors
The bare rescue on java.sql.DriverManager.getConnection swallowed any exception, including argument errors and unrelated SQL failures, and then tried the ORACLE_DRIVER fallback, obscuring the real error. Catch only Java::JavaSql::SQLException with a "no suitable driver" message (the one case the fallback was added for) and re-raise everything else so the original error surfaces. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1a2a80d commit f129738

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lib/plsql/jdbc_connection.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def self.create_raw(params)
5454
url = jdbc_connection_url(params)
5555
conn = begin
5656
java.sql.DriverManager.getConnection(url, params[:username], params[:password])
57-
rescue
57+
rescue Java::JavaSql::SQLException => e
58+
raise unless e.message =~ /no suitable driver/i
5859
# bypass DriverManager to work in cases where ojdbc*.jar
5960
# is added to the load path at runtime and not on the
6061
# system classpath

spec/spec_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def get_connection(user_number = 0)
9090
try_to_connect(Java::JavaSql::SQLException) do
9191
begin
9292
java.sql.DriverManager.getConnection(get_connection_url, database_user, database_password)
93-
rescue Java::JavaSql::SQLException
93+
rescue Java::JavaSql::SQLException => e
94+
raise unless e.message =~ /no suitable driver/i
9495
# bypass DriverManager to work in cases where ojdbc*.jar
9596
# is added to the load path at runtime and not on the
9697
# system classpath

0 commit comments

Comments
 (0)