fix: cleanup inconsistent and incorrect import error handling

Some notified errors didn't include error object. Import cli didn't fail
on failure and stack was reversed. Error notifications sometimes
included full error which makes errors unreadable in CLI and possibly
confusing for users. Also fixed missing classpath. Part of
LOG-3176
feat/tables
Gabriel Horner 2024-06-28 10:20:59 -04:00
parent 92134dec71
commit 9ee09372aa
3 changed files with 28 additions and 20 deletions

View File

@ -9,6 +9,7 @@
["fs" :as fs]
["fs/promises" :as fsp]
[nbb.core :as nbb]
[nbb.classpath :as cp]
[babashka.cli :as cli]
[logseq.graph-parser.exporter :as gp-exporter]
[logseq.common.graph :as common-graph]
@ -47,11 +48,14 @@
(println (string/join
"\n"
(map
#(str (:file %) (when (:line %) (str ":" (:line %)))
" calls #'"
(str (get-in % [:sci.impl/f-meta :ns]) "/" (get-in % [:sci.impl/f-meta :name])))
stack)))
(println (.-stack (get-in m [:ex-data :error])))))
#(str (:file %)
(when (:line %) (str ":" (:line %)))
(when (:sci.impl/f-meta %)
(str " calls #'" (get-in % [:sci.impl/f-meta :ns]) "/" (get-in % [:sci.impl/f-meta :name]))))
(reverse stack))))
(println (some-> (get-in m [:ex-data :error]) .-stack)))
(when (= :error (:level m))
(js/process.exit 1)))
(def default-export-options
{;; common options
@ -125,7 +129,7 @@
((juxt node-path/dirname node-path/basename) graph-dir'))
[(node-path/join (os/homedir) "logseq" "graphs") db-graph-dir])
file-graph' (resolve-path file-graph)
conn (outliner-cli/init-conn dir db-name)
conn (outliner-cli/init-conn dir db-name {:classpath (cp/get-classpath)})
directory? (.isDirectory (fs/statSync file-graph'))]
(p/do!
(if directory?

View File

@ -217,9 +217,9 @@
the property-schemas atom. If a property's :type changes, returns a map of
the schema attribute changed and how it changed e.g. `{:type {:from :default :to :url}}`"
[prop-val prop prop-val-text refs property-schemas macros]
;; Explicitly fail an unexpected case rather cause silent downstream failures
;; Explicitly fail an unexpected case rather than cause silent downstream failures
(when (and (coll? prop-val) (not (every? string? prop-val)))
(throw (ex-info "Import cannot infer schema of unknown property value"
(throw (ex-info (str "Import cannot infer schema of unknown property value " (pr-str prop-val))
{:value prop-val :property prop})))
(let [prop-type (cond (and (coll? prop-val)
(seq prop-val)
@ -805,8 +805,9 @@
(p/recur (export-doc-file (get doc-files (inc i)) conn <read-file options)
(inc i))))
(p/catch (fn [e]
(notify-user {:msg (str "Import has unexpected error:\n" e)
:level :error}))))))
(notify-user {:msg (str "Import has unexpected error:\n" (.-message e))
:level :error
:ex-data {:error e}}))))))
(defn- default-save-file [conn path content]
(ldb/transact! conn [{:file/path path
@ -827,8 +828,9 @@
(-> (<read-file custom-js)
(p/then #(<save-file repo-or-conn "logseq/custom.js" %)))))
(p/catch (fn [error]
(notify-user {:msg (str "Import unexpectedly failed while reading logseq files:\n" error)
:level :error}))))))
(notify-user {:msg (str "Import unexpectedly failed while reading logseq files:\n" (.-message error))
:level :error
:ex-data {:error error}}))))))
(defn- export-config-file
[repo-or-conn config-file <read-file {:keys [<save-file notify-user default-config]
@ -886,7 +888,7 @@
(p/catch
(<copy-asset-file file)
(fn [error]
(notify-user {:msg (str "Import failed on " (pr-str path) " with error:\n" error)
(notify-user {:msg (str "Import failed on " (pr-str path) " with error:\n" (.-message error))
:level :error
:ex-data {:path path :error error}}))))]
(when (seq asset-files)
@ -897,8 +899,9 @@
(p/recur (copy-asset (get asset-files (inc i)))
(inc i))))
(p/catch (fn [e]
(notify-user {:msg (str "Import has an unexpected error:\n" e)
:level :error})))))))
(notify-user {:msg (str "Import has an unexpected error:\n" (.-message e))
:level :error
:ex-data {:error e}})))))))
(defn- insert-favorites
"Inserts favorited pages as uuids into a new favorite page"

View File

@ -37,11 +37,12 @@
(println (string/join
"\n"
(map
#(str (:file %) (when (:line %) (str ":" (:line %)))
" calls #'"
(str (get-in % [:sci.impl/f-meta :ns]) "/" (get-in % [:sci.impl/f-meta :name])))
stack)))
(println (.-stack (get-in m [:ex-data :error])))))
#(str (:file %)
(when (:line %) (str ":" (:line %)))
(when (:sci.impl/f-meta %)
(str " calls #'" (get-in % [:sci.impl/f-meta :ns]) "/" (get-in % [:sci.impl/f-meta :name]))))
(reverse stack))))
(println (some-> (get-in m [:ex-data :error]) .-stack))))
(def default-export-options
{;; common options