mirror of
https://github.com/logseq/logseq.git
synced 2026-05-18 09:52:22 +00:00
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:
@@ -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]
|
||||
|
||||
@@ -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))))))
|
||||
|
||||
Reference in New Issue
Block a user