瀏覽代碼

fix: import single file from CLI didn't print error

Also improved CLI error reporting so sci stack is readable and
not filled with stack fn docstrings
Gabriel Horner 1 年之前
父節點
當前提交
5520bc1d33
共有 2 個文件被更改,包括 26 次插入11 次删除
  1. 25 10
      deps/graph-parser/script/db_import.cljs
  2. 1 1
      deps/graph-parser/src/logseq/graph_parser/exporter.cljs

+ 25 - 10
deps/graph-parser/script/db_import.cljs

@@ -12,6 +12,7 @@
             [babashka.cli :as cli]
             [logseq.graph-parser.exporter :as gp-exporter]
             [logseq.common.graph :as common-graph]
+            #_:clj-kondo/ignore
             [logseq.outliner.cli :as outliner-cli]
             [promesa.core :as p]))
 
@@ -38,6 +39,27 @@
           _ (fsp/mkdir parent-dir #js {:recursive true})]
     (fsp/copyFile (:path file) (node-path/join parent-dir (node-path/basename (:path file))))))
 
+(def default-export-options
+  {;; common options
+   :rpath-key ::rpath
+   :notify-user (fn notify-user [m]
+                  (println (:msg m))
+                  (println "Ex-data:" (pr-str (dissoc (:ex-data m) :error)))
+                  (when-let [stack (some-> (get-in m [:ex-data :error]) ex-data :sci.impl/callstack deref)]
+                    (println "Stacktrace:")
+                    (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)))))
+   :<read-file <read-file
+   ;; :set-ui-state prn
+   ;; config file options
+   ;; TODO: Add actual default
+   :default-config {}})
+
 (defn- import-file-graph-to-db
   "Import a file graph dir just like UI does. However, unlike the UI the
   exporter receives file maps containing keys :path and ::rpath since :path
@@ -47,16 +69,9 @@
         config-file (first (filter #(string/ends-with? (:path %) "logseq/config.edn") *files))
         _ (assert config-file "No 'logseq/config.edn' found for file graph dir")
         options (merge options
-                       {;; common options
-                        :rpath-key ::rpath
-                        :notify-user prn
-                        :<read-file <read-file
-                        ;; :set-ui-state prn
-                        ;; config file options
-                        ;; TODO: Add actual default
-                        :default-config {}
+                       default-export-options
                         ;; asset file options
-                        :<copy-asset (fn copy-asset [file]
+                       {:<copy-asset (fn copy-asset [file]
                                        (<copy-asset-file file db-graph-dir file-graph-dir))})]
     (gp-exporter/export-file-graph conn conn config-file *files options)))
 
@@ -70,7 +85,7 @@
 (defn- import-files-to-db
   "Import specific doc files for dev purposes"
   [file conn {:keys [files] :as options}]
-  (let [doc-options (gp-exporter/build-doc-options conn {:macros {}} options)
+  (let [doc-options (gp-exporter/build-doc-options conn {:macros {}} (merge options default-export-options))
         files' (mapv #(hash-map :path %)
                      (into [file] (map resolve-path files)))]
     (gp-exporter/export-doc-files conn files' <read-file doc-options)))

+ 1 - 1
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -773,7 +773,7 @@
         ;; returning val results in smoother ui updates
         m)
       (p/catch (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}})))))