0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-16 01:31:22 -05:00

Improve logging on worker and import process.

This commit is contained in:
Andrey Antukh 2022-01-17 18:41:02 +01:00 committed by Alonso Torres
parent 56dfdaecb7
commit 9cf5258053
4 changed files with 49 additions and 39 deletions

View file

@ -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

View file

@ -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)))))))

View file

@ -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?)

View file

@ -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))})))))))))