Skip to content

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

Log only the error message for failed queries (#77223)

Alexander Polyankinb48d367c212a
diff --git a/src/metabase/query_processor/middleware/catch_exceptions.clj b/src/metabase/query_processor/middleware/catch_exceptions.clj
index dd4a94ae7a5..5a35488c5b0 100644
--- a/src/metabase/query_processor/middleware/catch_exceptions.clj
+++ b/src/metabase/query_processor/middleware/catch_exceptions.clj
@@ -146,9 +146,8 @@
pool-saturated? (qp.error-type/connection-pool-saturated?
(:error_type formatted-exception))]
(when-not (or query-canceled? pool-saturated?)
- (log/errorf "Error processing query: %s\n%s"
- (or (:error formatted-exception) "Error running query")
- (u/pprint-to-str formatted-exception)))
+ (log/errorf "Error processing query: %s"
+ (or (:error formatted-exception) "Error running query")))
;; ensure always a message on the error otherwise FE thinks query was successful. (#23258, #23281)
(let [result (update formatted-exception
:error (fnil identity (trs "Error running query")))]
diff --git a/test/metabase/query_processor/middleware/catch_exceptions_test.clj b/test/metabase/query_processor/middleware/catch_exceptions_test.clj
index ce6272adeea..b6627011688 100644
--- a/test/metabase/query_processor/middleware/catch_exceptions_test.clj
+++ b/test/metabase/query_processor/middleware/catch_exceptions_test.clj
@@ -4,6 +4,8 @@
(:require
[clojure.test :refer :all]
[metabase.driver :as driver]
+ [metabase.lib.core :as lib]
+ [metabase.lib.metadata :as lib.metadata]
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.permissions.models.permissions-group :as perms-group]
[metabase.query-processor.compile :as qp.compile]
@@ -145,6 +147,25 @@
(is (=? [{:level :error, :message #"(?s)^Error processing query.*"}]
(messages))))))
+(deftest ^:synchronized error-log-excludes-stack-trace-and-query-test
+ (testing "the error log carries only the error message — no stack trace and nothing carrying the query/user data"
+ (mt/with-log-messages-for-level [messages [metabase.query-processor.middleware.catch-exceptions :error]]
+ (let [mp (mt/metadata-provider)
+ query (-> (lib/query mp (lib.metadata/table mp (mt/id :venues)))
+ (lib/filter (lib/= (lib.metadata/field mp (mt/id :venues :name)) "hunter2-query")))
+ result (catch-exceptions
+ (fn [] (throw (ex-info "boom" {:secret-in-ex-data "hunter2-ex-data"})))
+ query)]
+ (is (=? [{:level :error, :message "Error processing query: boom"}]
+ (messages)))
+ (testing "the userland response still has the full detail"
+ (is (=? {:status :failed
+ :error "boom"
+ :stacktrace vector?
+ :ex-data {:secret-in-ex-data "hunter2-ex-data"}
+ :json_query map?}
+ result)))))))
+
(deftest ^:parallel catch-exceptions-test
(testing "include-query-execution-info-test"
(testing "Should include info from QueryExecution if added to the thrown/raised Exception"