fulcrologic / guardrails

Efficient, hassle-free function call validation with a concise inline syntax for clojure.spec and Malli
Eclipse Public License 2.0
237 stars 25 forks source link

Invalid return type inferred in guardrails reporting and ambiguous meaning of report entry #46

Closed FieryCod closed 4 months ago

FieryCod commented 4 months ago

Dear @awkay,

Could you kindly help me understand the meaning of the below mentioned report in guardrails? Specifically it's hard for me to grok why the return type is considered to be LazySeq. I would expect (maybe wrongfully 🙈) guardrails to pinpoint the exact offending entry in returned vector like (io.blockether.datomic.core/join-migrations ...) => [entry-not-matching-schema].

Reproduction

Let's take into consideration the following schema in malli style:

(>def ::schematic
  [:map {}
   [:abc :string]])

(>def ::schematics
  [:vector ::schematic])

(>def ::schematics-list
  [:* ::schematic])

(>def ::migration
  [:map {}
   [:id :keyword]
   [:tx-data ::schematics]])

(>def ::migrations
  [:vector ::migration])

and let us define a simple function that takes migrations as a varargs and normalises them to vector of migrations

(>defn join-migrations
  [& migrations]
  [::schematics-list => [:maybe ::schematics]]
  (vec migrations))

(join-migrations 
  {:id :m1
   :tx-data [[:db/add "session" :session/id "someSessionId"]]}) ;; <-- see Guardrails Report

now I would expect guardrails to report the inferred type as vector and not a lazy-seq.

Guardrails Report

(please forgive me Calva comment marks)

; Guardrails:
;   (io.blockether.datomic.core/join-migrations {:id :m1, :tx-data [[:db/add "session" :session/id "someSessionId"]]})
;   Arg Errors: [{:abc ["missing required key"], :malli/error ["input remaining"]}]
;   Schema: [:catn
;            [:migrations
;             :io.blockether.datomic.core/schematics-list]]
;   GR functions on stack. (com.fulcrologic.guardrails.utils/last-failure 'io.blockether.datomic.core/join-migrations) for full stack:
;     (io.blockether.datomic.core/join-migrations ({:id :m1, :tx-data [[:db/add "session" :session/id "someSessionId"]]}))
;
;
;
;
;
; Guardrails: (ambiguous report)
;   (io.blockether.datomic.core/join-migrations ...) => clojure.lang.LazySeq@9e3791ee <-- LazySeq is ambiguous and misleading 
;   Return value {:abc ["missing required key"]}
;   Schema: [:maybe :io.blockether.datomic.core/schematics]
;   GR functions on stack. (com.fulcrologic.guardrails.utils/last-failure 'io.blockether.datomic.core/join-migrations) for full stack:
;     (io.blockether.datomic.core/join-migrations ({:id :m1, :tx-data [[:db/add "session" :session/id "someSessionId"]]}))

Hope this message finds you in good health. Thank you for all your hard work on guardrails. Cheers! Karol

awkay commented 4 months ago

Hi, please use Slack for support. You can use the #fulcro channel.

On this one it is complaining about your args, not your return type. The & is creating the lazy seq