Browse Source

fix: graph-parser test and lint

Removed test as no error handling is needed for ident generation. Also
removed all related downstream uses of catch for
db-ident/create-db-ident-from-name that are no longer needed
Gabriel Horner 1 year ago
parent
commit
3a4cc55cda

+ 2 - 7
deps/db/src/logseq/db/frontend/class.cljs

@@ -26,11 +26,6 @@
   facing messages when name is invalid"
   [db page-m]
   {:pre [(string? (:block/title page-m))]}
-  (let [db-ident (try (create-user-class-ident-from-name (:block/title page-m))
-                      (catch :default e
-                        (throw (ex-info (str e)
-                                        {:type :notification
-                                         :payload {:message "Failed to create class. Please try a different class name."
-                                                   :type :error}}))))
+  (let [db-ident (create-user-class-ident-from-name (:block/title page-m))
         db-ident' (db-ident/ensure-unique-db-ident db db-ident)]
-    (sqlite-util/build-new-class (assoc page-m :db/ident db-ident'))))
+    (sqlite-util/build-new-class (assoc page-m :db/ident db-ident'))))

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

@@ -310,7 +310,7 @@
   (when-not (and db (common-util/uuid-string? original-page-name)
                  (not (ldb/page? (d/entity db [:block/uuid (uuid original-page-name)]))))
     (let [db-based? (ldb/db-based-graph? db)
-          [page page-entity] (cond
+          [page _page-entity] (cond
                                (and original-page-name (string? original-page-name))
                                (let [original-page-name (common-util/remove-boundary-slashes original-page-name)
                                      [original-page-name page-name journal-day] (convert-page-if-journal original-page-name date-formatter)

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

@@ -43,14 +43,8 @@
   [db class-name all-idents]
   (if-let [db-ident (get @all-idents (keyword class-name))]
     {:db/ident db-ident}
-    (let [m (try
-              (db-class/build-new-class db {:block/title class-name
-                                            :block/name (common-util/page-name-sanity-lc class-name)})
-              (catch :default e
-                ;; Notify with more helpful error message
-                (if (= :notification (:type (ex-data e)))
-                  (throw (ex-info (str "Class " (pr-str class-name) " is an invalid class name. Please rename it.") {}))
-                  (throw e))))]
+    (let [m (db-class/build-new-class db {:block/title class-name
+                                          :block/name (common-util/page-name-sanity-lc class-name)})]
       (swap! all-idents assoc (keyword class-name) (:db/ident m))
       m)))
 
@@ -235,15 +229,9 @@
     (some? non-ref-char)))
 
 (defn- create-property-ident [db all-idents property-name]
-  (let [db-ident (try
-                   (->> (db-property/create-user-property-ident-from-name (name property-name))
-                        ;; TODO: Detect new ident conflicts within same page
-                        (db-ident/ensure-unique-db-ident db))
-                   (catch :default e
-                     ;; Notify with more helpful error message
-                     (if (re-find #"name.*empty" (str (ex-message e)))
-                       (throw (ex-info (str "Property " (pr-str property-name) " is an invalid property name. Please rename it.") {}))
-                       (throw e))))]
+  (let [db-ident (->> (db-property/create-user-property-ident-from-name (name property-name))
+                      ;; TODO: Detect new ident conflicts within same page
+                      (db-ident/ensure-unique-db-ident db))]
     (swap! all-idents assoc property-name db-ident)))
 
 (defn- get-ident [all-idents kw]

+ 1 - 17
deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

@@ -195,7 +195,7 @@
               set))))
 
     (testing "user properties"
-      (is (= 17
+      (is (= 18
              (->> @conn
                   (d/q '[:find [(pull ?b [:db/ident]) ...]
                          :where [?b :block/type "property"]])
@@ -430,22 +430,6 @@
              (readable-properties @conn (find-page-by-name @conn "Interstellar")))
           "tagged page has configured tag imported as a class"))))
 
-(deftest-async export-files-with-invalid-class-and-property-display-notifications
-  (p/let [file-graph-dir "test/resources/exporter-test-graph"
-          files (mapv #(node-path/join file-graph-dir %) ["journals/2024_07_24.md" "ignored/invalid-property-page.md"])
-          conn (d/create-conn db-schema/schema-for-db-based-graph)
-          _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
-          notifications (atom [])
-          _ (import-files-to-db files conn {:tag-classes ["123"]
-                                            :notify-user #(swap! notifications conj %)})]
-
-    (is (= [:error :error] (map :level @notifications))
-        "Error notifications for both invalid property and class")
-    (is (some #(re-find #"invalid class" %) (map :msg @notifications))
-        "Helpful message for invalid class")
-    (is (some #(re-find #"invalid property" %) (map :msg @notifications))
-        "Helpful message for invalid property")))
-
 (deftest-async export-files-with-property-classes-option
   (p/let [file-graph-dir "test/resources/exporter-test-graph"
           files (mapv #(node-path/join file-graph-dir %) ["journals/2024_02_23.md" "pages/url.md"])

+ 0 - 2
deps/graph-parser/test/resources/exporter-test-graph/ignored/invalid-property-page.md

@@ -1,2 +0,0 @@
-- b1
-123:: oops

+ 3 - 1
deps/graph-parser/test/resources/exporter-test-graph/journals/2024_07_24.md

@@ -1 +1,3 @@
-- invalid class example #123
+- unusual class example #123
+- unusual property example
+123:: works