fix: nonexistent string :date property value silently passes

and doesn't set anything. Now it errors clearly.
Also improve property validation for --{update/remove}-properties to
include property name
This commit is contained in:
Gabriel Horner
2026-03-23 15:57:29 -04:00
parent 26ac7f5aa5
commit 4263123e83
2 changed files with 27 additions and 9 deletions

View File

@@ -702,19 +702,20 @@
(string? value)
(resolve-page-id config repo value)
:else
(p/rejected (ex-info "node must be a uuid or page name" {:code :invalid-node :value value}))))
(p/rejected (ex-info "node must be a number, uuid or page name" {:code :invalid-node :value value}))))
(defn- resolve-date-page-id
[config repo value]
(when-not (string? value)
(throw (ex-info "date must be a string" {:code :invalid-date :value value})))
(throw (ex-info "date property value must be a string" {:code :invalid-date :value value})))
(p/let [journal (pull-entity config repo [:logseq.property.journal/title-format] :logseq.class/Journal)
formatter (or (:logseq.property.journal/title-format journal) "MMM do, yyyy")
formatters (date-time-util/safe-journal-title-formatters formatter)
journal-day (date-time-util/journal-title->int value formatters)
title (or (when journal-day
(date-time-util/int->journal-title journal-day formatter))
value)
_ (when-not journal-day
(throw (ex-info (str "invalid date property value: " (pr-str value))
{:code :invalid-date :value value})))
title (date-time-util/int->journal-title journal-day formatter)
page (ensure-page! config repo title)]
(if-let [id (:db/id page)]
id
@@ -793,22 +794,22 @@
ident (:db/ident entity)]
(cond
(nil? (:db/id entity))
(throw (ex-info "property not found"
(throw (ex-info (str "property not found: " (pr-str (name property-key)))
{:code :property-not-found
:property property-key}))
(not (property-entity? entity))
(throw (ex-info "target is not a property"
(throw (ex-info (str "This is not a property: " (pr-str (name property-key)))
{:code :invalid-property-target
:property property-key}))
(nil? ident)
(throw (ex-info "property not found"
(throw (ex-info (str "property not found: " (pr-str (name property-key)))
{:code :property-not-found
:property property-key}))
(not (property-entity-public? entity))
(throw (ex-info "property is not public"
(throw (ex-info (str "property is not public: " (pr-str (name property-key)))
{:code :property-not-public
:property ident}))

View File

@@ -109,3 +109,20 @@
(let [property {:schema {:type :default :cardinality :one}}
result (#'add-command/coerce-property-value-basic property true)]
(is (not (:ok? result))))))
(deftest test-resolve-date-page-id-rejects-invalid-date
(async done
(let [mock-invoke (fn [_ _ _ args]
(let [[_ _ lookup] args]
(p/resolved
(if (= lookup :logseq.class/Journal)
{}
{}))))]
(-> (p/with-redefs [transport/invoke mock-invoke]
(-> (#'add-command/resolve-date-page-id {} "demo" "not a date")
(p/then (fn [_] (is false "expected error for invalid date")))
(p/catch (fn [e]
(is (= :invalid-date (-> e ex-data :code)))
(is (string/includes? (ex-message e) "not a date"))))))
(p/catch (fn [e] (is false (str "unexpected error: " e))))
(p/finally done)))))