0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-14 02:58:39 -05:00

🐛 Fix incorrect frontend error handling on import code

This commit is contained in:
Andrey Antukh 2023-11-11 00:11:36 +01:00
parent 9b3964e6d7
commit d5e34df364

View file

@ -14,6 +14,7 @@
[app.common.geom.shapes.path :as gpa] [app.common.geom.shapes.path :as gpa]
[app.common.logging :as log] [app.common.logging :as log]
[app.common.media :as cm] [app.common.media :as cm]
[app.common.pprint :as pp]
[app.common.text :as ct] [app.common.text :as ct]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.repo :as rp] [app.main.repo :as rp]
@ -639,6 +640,7 @@
(let [error (or (.-message data) (tr "dashboard.import.analyze-error"))] (let [error (or (.-message data) (tr "dashboard.import.analyze-error"))]
(rx/of {:uri (:uri file) :error error})))))))))) (rx/of {:uri (:uri file) :error error}))))))))))
(defmethod impl/handler :import-files (defmethod impl/handler :import-files
[{:keys [project-id files features]}] [{:keys [project-id files features]}]
@ -648,52 +650,60 @@
zip-files (filter #(= "application/zip" (:type %)) files) zip-files (filter #(= "application/zip" (:type %)) files)
binary-files (filter #(= "application/octet-stream" (:type %)) files)] binary-files (filter #(= "application/octet-stream" (:type %)) files)]
(->> (rx/merge (rx/merge
(->> (create-files context zip-files) (->> (create-files context zip-files)
(rx/flat-map (rx/flat-map
(fn [[file data]] (fn [[file data]]
(->> (uz/load-from-url (:uri data)) (->> (uz/load-from-url (:uri data))
(rx/map #(-> context (assoc :zip %) (merge data))) (rx/map #(-> context (assoc :zip %) (merge data)))
(rx/merge-map (rx/merge-map
(fn [context] (fn [context]
;; process file retrieves a stream that will emit progress notifications ;; process file retrieves a stream that will emit progress notifications
;; and other that will emit the files once imported ;; and other that will emit the files once imported
(let [[progress-stream file-stream] (process-file context file)] (let [[progress-stream file-stream] (process-file context file)]
(rx/merge progress-stream (rx/merge progress-stream
(->> file-stream (->> file-stream
(rx/map (rx/map
(fn [file] (fn [file]
{:status :import-finish {:status :import-finish
:errors (:errors file) :errors (:errors file)
:file-id (:file-id data)}))))))) :file-id (:file-id data)})))))))
(rx/catch (fn [cause] (rx/catch (fn [cause]
(log/error :hint (ex-message cause) :file-id (:file-id data) :cause cause) (log/error :hint (ex-message cause)
(rx/of {:status :import-error :file-id (:file-id data)
:file-id (:file-id data) :cause cause)
:error (ex-message cause) (rx/of {:status :import-error
:error-data (ex-data cause)}))))))) :file-id (:file-id data)
:error (ex-message cause)
:error-data (ex-data cause)})))))))
(->> (rx/from binary-files) (->> (rx/from binary-files)
(rx/flat-map (rx/flat-map
(fn [data] (fn [data]
(->> (http/send! (->> (http/send!
{:uri (:uri data) {:uri (:uri data)
:response-type :blob :response-type :blob
:method :get}) :method :get})
(rx/map :body) (rx/map :body)
(rx/mapcat #(rp/cmd! :import-binfile {:file % (rx/mapcat #(rp/cmd! :import-binfile {:file % :project-id project-id}))
:project-id project-id})) (rx/map (fn [_]
(rx/map {:status :import-finish
(fn [_] :file-id (:file-id data)}))
{:status :import-finish (rx/catch (fn [cause]
:file-id (:file-id data)}))))))) (log/error :hint "unexpected error on import process"
:project-id project-id
::log/sync? true)
;; TODO: consider do thi son logging directly ?
(rx/catch (fn [cause] (when (map? cause)
(log/error :hint "unexpected error on import process" (println "Error data:")
:project-id project-id (pp/pprint (dissoc cause :explain) {:level 2 :length 10}))
:cause cause)
(if (map? cause)
(js/console.error (pr-str cause))
(js/console.error cause)))))))
(when (string? (:explain cause))
(js/console.log (:explain cause)))
(rx/of {:status :import-error
:file-id (:file-id data)
:error (:hint cause)
:error-data cause}))))))))))