Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in validation of where clauses #579

Open
mpoffald opened this issue Sep 19, 2023 · 0 comments
Open

Regression in validation of where clauses #579

mpoffald opened this issue Sep 19, 2023 · 0 comments

Comments

@mpoffald
Copy link
Contributor

mpoffald commented Sep 19, 2023

In the process of working on #564, I found some error messages that are not caused by malli. These are issues we are failing to catch in validation in the first place in v3, but we used to catch in v2.

  1. Extra nesting in where clause:
'{:select {?s [*]}
  :where  [[[?s ?p ?o]]]}
  ;;=>
 #error
{:cause "class clojure.lang.PersistentVector cannot be cast to class java.lang.CharSequence (clojure.lang.PersistentVector is in unnamed module of loader 'app'; java.lang.CharSequence is in module java.base of loader 'bootstrap')"
 :via
 [{:type clojure.lang.ExceptionInfo
   :message "Error attempting to parse iri: [?s ?p ?o]"
   :data {:status 400, :error :json-ld/invalid-iri}
   :at [fluree.json_ld.impl.iri$parse_prefix invokeStatic "iri.cljc" 44]}
  {:type java.lang.ClassCastException
   :message "class clojure.lang.PersistentVector cannot be cast to class java.lang.CharSequence (clojure.lang.PersistentVector is in unnamed module of loader 'app'; java.lang.CharSequence is in module java.base of loader 'bootstrap')"
   :at [clojure.core$re_matcher invokeStatic "core.clj" 4874]}]}
  1. Insufficient entries in where clause:
'{:select {?s [*]}
 :where  [[?s]]}
;;=>
#error
{:cause "Cannot invoke \"java.lang.CharSequence.length()\" because \"this.text\" is null"
:via
[{:type clojure.lang.ExceptionInfo
  :message "Error attempting to parse iri: "
  :data {:status 400, :error :json-ld/invalid-iri}
  :at [fluree.json_ld.impl.iri$parse_prefix invokeStatic "iri.cljc" 44]}
 {:type java.lang.NullPointerException
  :message "Cannot invoke \"java.lang.CharSequence.length()\" because \"this.text\" is null"
  :at [java.util.regex.Matcher getTextLength "Matcher.java" 1769]}]}

In v2 we caught these early and gave good hints about what might be wrong:

(from https://github.com/fluree/db/blob/maintenance/v2/src/fluree/db/query/analytical.cljc#L873)

(if (sequential? (first clause))
  (throw (ex-info (str "Invalid where clause, it appears you have an extra nested vector here: " clause)
                  {:status 400 :error :db/invalid-query}))
  (throw (ex-info (str "Invalid where clause, it should have 2+ tuples but instead found: " clause)
                  {:status 400 :error :db/invalid-query})) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant