diff --git a/src/metabase/driver/mongo.clj b/src/metabase/driver/mongo.clj index 6d57b4239114b3191c7a31f259f8b1e5eac2fafc..6308e916aac27c35cf716d27a33e4b763de5b7bb 100644 --- a/src/metabase/driver/mongo.clj +++ b/src/metabase/driver/mongo.clj @@ -1,6 +1,7 @@ (ns metabase.driver.mongo "MongoDB Driver." (:require [clojure.set :as set] + [clojure.tools.logging :as log] (monger [collection :as mc] [command :as cmd] [conversion :as conv] @@ -118,16 +119,19 @@ (defn- describe-table [table] (with-mongo-connection [^com.mongodb.DB conn (table/database table)] ;; TODO: ideally this would take the LAST set of rows added to the table so we could ensure this data changes on reruns - (let [parsed-rows (->> (mc/find-maps conn (:name table)) - (take driver/max-sync-lazy-seq-results) - (reduce - (fn [field-defs row] - (loop [[k & more-keys] (keys row) - fields field-defs] - (if-not k - fields - (recur more-keys (update fields k (partial update-field-attrs (k row))))))) - {}))] + (let [parsed-rows (try + (->> (mc/find-maps conn (:name table)) + (take driver/max-sync-lazy-seq-results) + (reduce + (fn [field-defs row] + (loop [[k & more-keys] (keys row) + fields field-defs] + (if-not k + fields + (recur more-keys (update fields k (partial update-field-attrs (k row))))))) + {})) + (catch Throwable t + (log/error (format "Error introspecting collection: %s" (:name table)) t)))] {:name (:name table) :fields (set (for [field (keys parsed-rows)] (describe-table-field field (field parsed-rows))))}))) diff --git a/src/metabase/util.clj b/src/metabase/util.clj index 081b13000d645dba7e05e9a12a52333ab5de6601..97f9ecc50ac1aad0abba2a5498c402adc2ba26d2 100644 --- a/src/metabase/util.clj +++ b/src/metabase/util.clj @@ -365,8 +365,9 @@ (when-let [^java.net.URL url (try (java.net.URL. string) (catch java.net.MalformedURLException _ nil))] - (and (re-matches #"^https?$" (.getProtocol url)) ; these are both automatically downcased - (re-matches #"^.+\..{2,}$" (.getAuthority url))))))) ; this is the part like 'google.com'. Make sure it contains at least one period and 2+ letter TLD + (when (and (.getProtocol url) (.getAuthority url)) + (and (re-matches #"^https?$" (.getProtocol url)) ; these are both automatically downcased + (re-matches #"^.+\..{2,}$" (.getAuthority url)))))))) ; this is the part like 'google.com'. Make sure it contains at least one period and 2+ letter TLD (def ^:private ^:const host-up-timeout "Timeout (in ms) for checking if a host is available with `host-up?` and `host-port-up?`." diff --git a/test/metabase/util_test.clj b/test/metabase/util_test.clj index 44821c9e11ac8b5968507f0e4bbe1357fde68376..f3b3b1d2d26fbe1d7863aa3815cf79c23433de52 100644 --- a/test/metabase/util_test.clj +++ b/test/metabase/util_test.clj @@ -113,7 +113,7 @@ (expect false (is-url? "http://metabasecom")) ; no period / TLD (expect false (is-url? "http://.com")) ; no domain (expect false (is-url? "http://google.")) ; no TLD - +(expect false (is-url? "http:/")) ; nil .getAuthority needs to be handled or NullPointerException ;;; ## tests for RPARTIAL