From 51de2707a76fd5237ea5c6ac04ca46861cbaa73d Mon Sep 17 00:00:00 2001 From: Marcela Poffald Date: Tue, 24 Oct 2023 20:47:40 -0500 Subject: [PATCH 1/2] define set of top-level-keys for error messages When querying via h-a-g/server, the query request schema wraps the fql schema in a dispatch (fql vs sparql). So we can't assume that the first keyword is the actual top-level key of the query. --- src/fluree/db/validation.cljc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/fluree/db/validation.cljc b/src/fluree/db/validation.cljc index 300dc86ee..b8fb68e0a 100644 --- a/src/fluree/db/validation.cljc +++ b/src/fluree/db/validation.cljc @@ -160,12 +160,22 @@ (recur (pop path) (last path) path' p' m') (when m [(if (seq in) (mu/path->in schema path') (me/error-path error options)) m' p'])))))) +(def top-level-query-keys + #{:select + :where + :group-by + :groupBy + :order-by + :orderBy + :commit-details + :t + :history}) + (defn format-error [explained error error-opts] (let [{:keys [path value]} error - top-level-key (when-not (= ::m/extra-key (:type error)) - (some-> (first (filter keyword? path)) - name)) + top-level-key (some-> (first (filter top-level-query-keys path)) + name) top-level-message (when top-level-key (str "Error in value for \"" top-level-key "\"")) [_ root-message] (resolve-root-error-for-in From 703512960cb160c1abcdb38f2e4ddee5d4ef2243 Mon Sep 17 00:00:00 2001 From: Marcela Poffald Date: Wed, 25 Oct 2023 12:54:57 -0500 Subject: [PATCH 2/2] rm extraneous comma --- src/fluree/db/query/history.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fluree/db/query/history.cljc b/src/fluree/db/query/history.cljc index bb50ab42b..9d65767fa 100644 --- a/src/fluree/db/query/history.cljc +++ b/src/fluree/db/query/history.cljc @@ -79,7 +79,7 @@ (if at (not (or from to)) (or from to)))] - [:fn {:error/message "\"from\" value must be less than or equal to \"to\" value,"} + [:fn {:error/message "\"from\" value must be less than or equal to \"to\" value"} (fn [{:keys [from to]}] (if (and (number? from) (number? to)) (<= from to) true))]]]]