fluree / db

Fluree database library

Home Page:https://fluree.github.io/db/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regression in validation of where clauses

mpoffald opened this issue · comments

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})) )