From 9cf525805313ce94b84caff9898e2625581d7cea Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 17 Jan 2022 18:41:02 +0100 Subject: [PATCH] :sparkles: Improve logging on worker and import process. --- common/src/app/common/logging.cljc | 10 ++- .../src/app/main/ui/dashboard/import.cljs | 2 +- frontend/src/app/worker.cljs | 5 ++ frontend/src/app/worker/import.cljs | 71 +++++++++---------- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/common/src/app/common/logging.cljc b/common/src/app/common/logging.cljc index e6087b2ed8..033de85cb7 100644 --- a/common/src/app/common/logging.cljc +++ b/common/src/app/common/logging.cljc @@ -298,7 +298,7 @@ #?(:cljs (defn default-handler - [{:keys [message level logger-name]}] + [{:keys [message level logger-name exception] :as params}] (let [header-styles (str "font-weight: 600; color: " (level->color level)) normal-styles (str "font-weight: 300; color: " (get colors :gray6)) level-name (level->short-name level) @@ -319,7 +319,13 @@ (js/console.error v)))) (js/console.groupEnd message)) (let [message (str header "%c" (pr-str message))] - (js/console.log message header-styles normal-styles)))))))) + (js/console.log message header-styles normal-styles))))) + + (when exception + (when-let [data (ex-data exception)] + (js/console.error "cause data:" (pr-str data))) + (js/console.error (.-stack exception)))))) + #?(:cljs (defn record->map diff --git a/frontend/src/app/main/ui/dashboard/import.cljs b/frontend/src/app/main/ui/dashboard/import.cljs index 014b0b7d38..6edfbb955b 100644 --- a/frontend/src/app/main/ui/dashboard/import.cljs +++ b/frontend/src/app/main/ui/dashboard/import.cljs @@ -248,7 +248,7 @@ (rx/delay-emit emit-delay) (rx/subs (fn [{:keys [uri data error] :as msg}] - (log/debug :msg msg) + (log/debug :uri uri :data data :error error) (if (some? error) (swap! state update :files set-analyze-error uri) (swap! state update :files set-analyze-result uri data))))))) diff --git a/frontend/src/app/worker.cljs b/frontend/src/app/worker.cljs index 496c00415b..ea54c39314 100644 --- a/frontend/src/app/worker.cljs +++ b/frontend/src/app/worker.cljs @@ -6,6 +6,7 @@ (ns app.worker (:require + [app.common.logging :as log] [app.common.spec :as us] [app.common.transit :as t] [app.worker.export] @@ -18,6 +19,10 @@ [cljs.spec.alpha :as s] [promesa.core :as p])) +(log/initialize!) +(log/set-level! :root :warn) +(log/set-level! :app :info) + ;; --- Messages Handling (s/def ::cmd keyword?) diff --git a/frontend/src/app/worker/import.cljs b/frontend/src/app/worker/import.cljs index 11473c0af6..5dcfa3f522 100644 --- a/frontend/src/app/worker/import.cljs +++ b/frontend/src/app/worker/import.cljs @@ -124,13 +124,12 @@ [context] (let [resolve (:resolve context) file-id (resolve (:file-id context))] - (rp/mutation - :create-temp-file - {:id file-id - :name (:name context) - :is-shared (:shared context) - :project-id (:project-id context) - :data (-> cp/empty-file-data (assoc :id file-id))}))) + (rp/mutation :create-temp-file + {:id file-id + :name (:name context) + :is-shared (:shared context) + :project-id (:project-id context) + :data (-> cp/empty-file-data (assoc :id file-id))}))) (defn link-file-libraries "Create a new file on the back-end" @@ -250,7 +249,6 @@ (defn process-import-node [context file node] - (let [type (cip/get-type node) close? (cip/close? node)] (if close? @@ -480,10 +478,9 @@ (rx/concat (->> (rx/from files) (rx/map #(merge context %)) - (rx/flat-map - (fn [context] - (->> (create-file context) - (rx/map #(vector % (first (get data (:file-id context))))))))) + (rx/flat-map (fn [context] + (->> (create-file context) + (rx/map #(vector % (first (get data (:file-id context))))))))) (->> (rx/from files) (rx/map #(merge context %)) @@ -508,31 +505,33 @@ (let [context {:project-id project-id :resolve (resolve-factory)}] + (->> (create-files context files) - (rx/catch #(.error js/console "IMPORT ERROR" (clj->js %))) (rx/flat-map (fn [[file data]] - (->> (rx/concat - (->> (uz/load-from-url (:uri data)) - (rx/map #(-> context (assoc :zip %) (merge data))) - (rx/flat-map - (fn [context] - ;; process file retrieves a stream that will emit progress notifications - ;; and other that will emit the files once imported - (let [[progress-stream file-stream] (process-file context file)] - (rx/merge - progress-stream - (->> file-stream - (rx/map - (fn [file] - {:status :import-finish - :errors (:errors file) - :file-id (:file-id data)}))))))))) + (->> (uz/load-from-url (:uri data)) + (rx/map #(-> context (assoc :zip %) (merge data))) + (rx/flat-map + (fn [context] + ;; process file retrieves a stream that will emit progress notifications + ;; and other that will emit the files once imported + (let [[progress-stream file-stream] (process-file context file)] + (rx/merge progress-stream + (->> file-stream + (rx/map + (fn [file] + {:status :import-finish + :errors (:errors file) + :file-id (:file-id data)}))))))) + (rx/catch (fn [cause] + (log/error :hint (ex-message cause) :file-id (:file-id data) :cause cause) + (rx/of {:status :import-error + :file-id (:file-id data) + :error (ex-message cause) + :error-data (ex-data cause)})))))) + + (rx/catch (fn [cause] + (log/error :hint "unexpected error on import process" + :project-id project-id + :cause cause)))))) - (rx/catch - (fn [err] - (.error js/console "ERROR" (str (:file-id data)) (clj->js err) (clj->js (.-data err))) - (rx/of {:status :import-error - :file-id (:file-id data) - :error (.-message err) - :error-data (clj->js (.-data err))})))))))))