Fork me on GitHub
#fulcro
<
2024-04-03
>
sheluchin15:04:55

(>defn with-opts
  [x & {:as opts}]
  [int? (s/keys*) => nil?]
  nil)

(defn with-opts-no-g
  [x & {:as opts}]
  nil)

(comment
  (with-opts 1 1)
  ; Execution error (IllegalArgumentException) at com.fulcrologic.guardrails.core/run-check (core.cljc:109).
  ; Don't know how to create ISeq from: java.lang.Long
  (with-opts-no-g 1 1))
  ; nil
Is this a bug in Guardrails 1.2.5?

tony.kay19:04:56

seems like it might be

tony.kay19:04:16

thought doesn’t s/keys* require enought things to make a map?

tony.kay19:04:35

so technically you’re calling it wit too few args

sheluchin23:04:05

I think a bare s/keys* is valid just like a bare s/keys is so it should work. > Thus a bare (s/keys) is valid and will check all attributes of a map without checking which keys are required or optional. > keys* has the same syntax and semantics as keys but can be embedded inside a sequential regex structure.

(s/conform (s/or :map (s/keys :req [::x])
                   :opts (s/keys*))
             {::x 1})
  ; [:map #:com.example.playgrounds.spec{:x 1}]
  (s/conform (s/or :map (s/keys :req [::x])
                   :opts (s/keys*))
             [::x 1]))
  ; [:opts #:com.example.playgrounds.spec{:x 1}]

tony.kay23:04:52

You have a function that says it wants x. and then wants to make a map out of the remaining varargs…thus, don’t t hose remaining args have to be an EVEN number of them? You’re calling it with a single extra arg, which is odd.

sheluchin23:04:01

You're right, that is odd, but the behaviour with Guardrails is different than without:

(defn with-opts-no-g
  [x & {:as opts}]
  opts)

(comment
  (with-opts-no-g 1) ; nil
  (with-opts-no-g 1 2) ; 2
  (with-opts-no-g 1 2 3) ; {2 3}
  (with-opts-no-g 1 2 3 4))
  ; Execution error (IllegalArgumentException) at com.example.playgrounds.spec/with-opts-no-g (REPL:71).
  ; Don't know how to create ISeq from: java.lang.Long

sheluchin23:04:50

Not sure if that's worth pursuing as it is misuse in the first place, but the difference between Guardrails and without is something.

tony.kay23:04:35

the question I have is: does it work right when called right?

tony.kay23:04:38

that spec just isn’t valid if called with the wrong number of args…and it is probably clojure spec dying on it

tony.kay23:04:05

if so, then the problem is that GR should try/catch the validation, and report when the validator “crashes”