当某个函数的仪器仪表失败时,explain-data会包含“调用者”信息。然而,如果仪器仪表失败是针对宏的,则此信息将缺失。
这个评论使我相信,预期行为是使explain-data包含此信息,以便第三方错误打印机可以显示它。
在下面的重现中,我设置了自定义打印机来仅捕获原始explain-data(这不是一个有用的打印机,只是用来显示正在发生的事情)
重现
(require '[clojure.spec.alpha :as s])
(require '[clojure.spec.test.alpha :as st])
(require '[clojure.specs.alpha :as s])
(s/fdef my-fn
:args (s/cat :x int?))
(defn my-fn [x]
x)
(s/fdef my-macro
:args (s/cat :x int?))
(defmacro my-macro [x]
x)
(st/instrument)
(def !ed (atom nil))
(set! s/*explain-out* (fn [ed]
(reset! !ed ed)))
(my-fn "")
@!ed
;; {:clojure.spec.alpha/problems [{:path [:args :x], :pred clojure.core/int?, :val "", :via [], :in [0]}], :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x72029b0e "clojure.spec.alpha$regex_spec_impl$reify__2436@72029b0e"], :clojure.spec.alpha/value (""), :clojure.spec.alpha/args (""), :clojure.spec.alpha/failure :instrument, :clojure.spec.test.alpha/caller {:file "form-init8333540581183382896.clj", :line 548, :var-scope expound.alpha/eval27394}}
;; ^--- 注意这里有一个 :clojure.spec.test.alpha/caller条目
(my-macro "")
@!ed
;; #:clojure.spec.alpha{:problems [{:path [:args :x], :pred clojure.core/int?, :val "", :via [], :in [0]}], :spec #object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x479a6a73 "clojure.spec.alpha$regex_spec_impl$reify__2436@479a6a73"], :value (""), :args ("")}
;; ^--- 没有调用者信息