Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

return false instead of throw (#65225)

Riley Thompson1eb96fc1ece5
diff --git a/modules/drivers/starburst/src/metabase/driver/starburst.clj b/modules/drivers/starburst/src/metabase/driver/starburst.clj
index c688d1a3154..99a986856b7 100644
--- a/modules/drivers/starburst/src/metabase/driver/starburst.clj
+++ b/modules/drivers/starburst/src/metabase/driver/starburst.clj
@@ -454,12 +454,10 @@
;; but we can't check the type directly since the relevant io.trino.spi.* classes are not
;; included in trino-jdbc. We check the vendor-specific error code instead.
;; See HiveMetadata.java and UnknownTableTypeException.java in trinodb/trino
- (if (= 133001 (.getErrorCode e))
- (do
- (log/debugf e "Table %s.%s is not accessible through this catalog (mixed catalog table type)"
- table-schema table-name)
- false)
- (throw e)))))
+ (when (= 133001 (.getErrorCode e))
+ (log/debugf e "Table %s.%s is not accessible through this catalog (mixed catalog table type)"
+ table-schema table-name))
+ false)))
(defn- describe-schema
"Gets a set of maps for all tables in the given `catalog` and `schema`."
diff --git a/modules/drivers/starburst/test/metabase/driver/starburst_test.clj b/modules/drivers/starburst/test/metabase/driver/starburst_test.clj
index d2b170889a8..730f4382b7b 100644
--- a/modules/drivers/starburst/test/metabase/driver/starburst_test.clj
+++ b/modules/drivers/starburst/test/metabase/driver/starburst_test.clj
@@ -64,20 +64,17 @@
(is (false? (sql-jdbc.sync.interface/have-select-privilege?
:starburst mock-conn "sales_data" "iceberg_table")))))
- (testing "Rethrows SQLException for non-mixed-catalog errors"
+ (testing "Returns false for non-mixed-catalog errors"
(let [mock-conn (reify Connection
(getCatalog [_] "hive")
(prepareStatement [_ sql]
(is (= "DESCRIBE \"hive\".\"sales_data\".\"restricted_table\"" sql))
(reify PreparedStatement
(executeQuery [_]
- ;; This is a regular permission error, not a mixed catalog issue (different error code)
(throw (SQLException. "Access Denied: Cannot access table restricted_table" nil 42000)))
(close [_] nil))))]
- ;; This should throw the exception rather than returning false
- (is (thrown? SQLException
- (sql-jdbc.sync.interface/have-select-privilege?
- :starburst mock-conn "sales_data" "restricted_table")))))))
+ (is (false? (sql-jdbc.sync.interface/have-select-privilege?
+ :starburst mock-conn "sales_data" "restricted_table")))))))
(deftest describe-database-test
(mt/test-driver :starburst
@@ -434,3 +431,22 @@
(is (false? (.isClosed prepared-stmt)))
(.close stmt)
(is (true? (.isClosed prepared-stmt)))))))))
+
+(deftest have-select-privilege-doesnt-throw-test
+ (mt/test-driver :starburst
+ (testing "have-select-privilege? returns true if table exists"
+ (sql-jdbc.execute/do-with-connection-with-options
+ driver/*driver*
+ (mt/db)
+ nil
+ (fn [^Connection conn]
+ (is (true?
+ (sql-jdbc.sync.interface/have-select-privilege? driver/*driver* conn "default" "products"))))))
+ (testing "have-select-privilege? returns false if table does not exist"
+ (sql-jdbc.execute/do-with-connection-with-options
+ driver/*driver*
+ (mt/db)
+ nil
+ (fn [^Connection conn]
+ (is (false?
+ (sql-jdbc.sync.interface/have-select-privilege? driver/*driver* conn "default" "fake_table"))))))))
diff --git a/src/metabase/sync/fetch_metadata.clj b/src/metabase/sync/fetch_metadata.clj
index 1ade3a89c64..1c494987411 100644
--- a/src/metabase/sync/fetch_metadata.clj
+++ b/src/metabase/sync/fetch_metadata.clj
@@ -19,7 +19,7 @@
`(try
~@body
(catch Throwable e#
- (log/errorf e# "Error while fetching metdata with '%s'" ~function-name)
+ (log/errorf e# "Error while fetching metadata with '%s'" ~function-name)
(throw e#))))
(mu/defn db-metadata :- i/DatabaseMetadata