Fork me on GitHub
#malli
<
2022-12-23
>
armed11:12:02

Hi, is there a way to apply malli function schemas (`m/=>`) to macros? Minimal example:

(def ?ErrOrOpts
  [:or
   [:fn {:error/message "should be Throwable"} throwable?]
   [:map {:error/message "should be a map"}
    [:throwable [:fn {:error/message "should be Throwable"} throwable?]]]])

(def ?LogArgs
  [:function
   [:=> [:cat ?Message] :nil]
   [:=> [:cat ?Message ?ErrOrOpts] :nil]])

(m/=> foo ?LogArgs)
(defmacro foo
  ([msg] nil)
  ([msg err-or-opts] nil))

(comment 
  (foo "hello")
  )
blows up with:
Invalid function arity (3):

  ((foo "hello") nil "hello")
....
It seems that macro call is wrapped

armed11:12:11

the workaround seems is prepend args with two :any, e.g. [:=> [:cat :any :any <real marco args>] :nil]

armed11:12:17

but error messages will contain all that extra stuff

armed13:12:23

seems it is not possible to instrument macros properly, better to instrument functions which macro calls