fix(cli): query --inputs fails unexpectedly for incorrect

input. `--inputs=b1` was throwing 'No protocol method ICounted.-count defined'
instead of intended error message
This commit is contained in:
Gabriel Horner
2026-04-02 14:57:20 -04:00
parent 319247beb3
commit 2ebf226deb
2 changed files with 33 additions and 20 deletions

View File

@@ -248,36 +248,35 @@
query-result
(let [inputs-text (some-> (:inputs options) string/trim)
inputs-result (when (seq inputs-text)
(parse-edn "inputs" inputs-text))
named-inputs (when-let [entry (:entry query-result)]
(normalize-named-inputs entry (or (:value inputs-result) [])))]
(parse-edn "inputs" inputs-text))]
(cond
(and inputs-result (not (:ok? inputs-result)))
inputs-result
(and named-inputs (not (:ok? named-inputs)))
named-inputs
(and inputs-result (not (vector? (:value inputs-result))))
{:ok? false
:error {:code :invalid-options
:message "inputs must be a vector"}}
:else
(let [inputs (normalize-task-search-inputs
(:entry query-result)
(or (:value named-inputs)
(:value inputs-result)
[]))
validated (validate-recent-updated-inputs (:entry query-result) inputs)]
(if-not (:ok? validated)
validated
{:ok? true
:action {:type :query
:repo repo
:graph (core/repo->graph repo)
:query (:value query-result)
:inputs (:value validated)}}))))))))))
(let [named-inputs (when-let [entry (:entry query-result)]
(normalize-named-inputs entry (or (:value inputs-result) [])))]
(if (and named-inputs (not (:ok? named-inputs)))
named-inputs
(let [inputs (normalize-task-search-inputs
(:entry query-result)
(or (:value named-inputs)
(:value inputs-result)
[]))
validated (validate-recent-updated-inputs (:entry query-result) inputs)]
(if-not (:ok? validated)
validated
{:ok? true
:action {:type :query
:repo repo
:graph (core/repo->graph repo)
:query (:value query-result)
:inputs (:value validated)}}))))))))))))
(defn build-list-action
[_options _repo]

View File

@@ -4,6 +4,7 @@
[logseq.cli.command.add :as add-command]
[logseq.cli.command.graph :as graph-command]
[logseq.cli.command.list :as list-command]
[logseq.cli.command.query :as query-command]
[logseq.cli.command.show :as show-command]
[logseq.cli.command.sync :as sync-command]
[logseq.cli.commands :as commands]
@@ -3174,3 +3175,16 @@
(is (= 2 (get-in result [:human :graph-list :legacy-count])))))
(p/catch (fn [e] (is false (str "unexpected error: " e))))
(p/finally done))))
(deftest test-query-build-action-non-vector-inputs
(testing "non-vector inputs gives explicit error"
(let [result (query-command/build-action {:name "block-search" :inputs "b1"}
"test-repo" {})]
(is (false? (:ok? result)))
(is (= :invalid-options (get-in result [:error :code])))
(is (= "inputs must be a vector" (get-in result [:error :message])))))
(testing "valid vector inputs succeeds"
(let [result (query-command/build-action {:name "block-search" :inputs "[\"daily\"]"}
"test-repo" {})]
(is (true? (:ok? result))))))