Uploaded image for project: 'Clojure'
  1. CLJ-2166

[spec] instrument exception doesn't contain function name in ex-data

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Completed
    • Affects versions: Release 1.9
    • Fix versions: Release 1.10
    • Labels:
    • Approval:
      Ok
    • Patch:
      Code

      Description

      When an instrumented function fails, it throws an IExceptionInfo. The ex-data of this exception contains the arguments that failed, but not the function that was called.

      (require '[clojure.spec.alpha :as s] '[clojure.spec.test.alpha :as stest])
      (defn foo [x] (+ x 1))
      (s/fdef foo :args (s/cat :x number?))
      (stest/instrument `foo)
      (foo "x")  ;; ExceptionInfo Call to #'user/foo did not conform to spec:
      (ex-data *e)
      
      {:clojure.spec.alpha/problems
       [{:path [:args :x], :pred number?, :val "x", :via [], :in [0]}],
       :clojure.spec.alpha/args ("x"),
       :clojure.spec.alpha/failure :instrument,
       :clojure.spec.test.alpha/caller
       {:file "form-init1493151512736136730.clj",
        :line 101,
        :var-scope user/eval23284}}
      

      *Proposed: Add an extra key clojure.spec.alpha/fn that has the symbol of the var under instrumentation.

      After:

      user> (ex-data *e)
      =>
      {:clojure.spec.alpha/problems [{:path [:args :x],
                                      :pred clojure.core/number?,
                                      :val "x",
                                      :via [],
                                      :in [0]}],
       :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__1210
                                        0x4db4a004
                                        "clojure.spec.alpha$regex_spec_impl$reify__1210@4db4a004"],
       :clojure.spec.alpha/value ("x"),
       :clojure.spec.alpha/fn user/foo,
       :clojure.spec.alpha/args ("x"),
       :clojure.spec.alpha/failure :instrument,
       :clojure.spec.test.alpha/caller {:file "form-init2105027941758372775.clj",
                                        :line 1,
                                        :var-scope user/eval1050}}
      

      Patch: clj2166.patch

      Screened by: Alex Miller

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              5 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: