Skip to content

Commit

Permalink
Merge pull request #897 from armed/master
Browse files Browse the repository at this point in the history
fix show function FQN in instrumentation exception
  • Loading branch information
ikitommi authored Aug 8, 2023
2 parents 6843160 + abab957 commit 386eb3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,12 @@
(defn -register-function-schema!
([ns name ?schema data] (-register-function-schema! ns name ?schema data :clj function-schema))
([ns name ?schema data key f]
(swap! -function-schemas* assoc-in [key ns name] (merge data {:schema (f ?schema), :ns ns, :name name}))))
(try
(swap! -function-schemas* assoc-in [key ns name] (merge data {:schema (f ?schema), :ns ns, :name name}))
(catch #?(:clj Throwable :cljs :default) ex
(throw (ex-info
(str "Schema error when insrumenting function: " ns "/" name " - " (ex-message ex))
(ex-data ex)))))))

#?(:clj
(defmacro => [given-sym value]
Expand Down
27 changes: 27 additions & 0 deletions test/malli/dev_err_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns malli.dev-err-test
(:require [clojure.test :refer [deftest is testing]]
[malli.dev :as md]
[malli.dev.pretty :as pretty]))

(defn plus-err
[x] (inc x))

(defn ->plus-err [] plus-err)

(deftest start!-err-test
(testing "malli.dev/start!"
(testing "without starting"
(is (thrown? ClassCastException ((->plus-err) "2")))
(is (= 7 ((->plus-err) 6))))

(testing "instrumentation shema error when starting"
;; append metadata only during test to prevent conflicts with other tests
(alter-meta! #'plus-err #(assoc % :malli/schema [:=> [:cat [:vector]] [:int {:max 6}]]))
(try
(is (thrown-with-msg?
Exception #"Schema error when insrumenting function: malli.dev-err-test/plus-err - :malli.core/child-error"
(md/start! {:ns *ns*})))
(catch Throwable _
(md/stop!)))
(alter-meta! #'plus-err #(dissoc % :malli/schema)))))

0 comments on commit 386eb3f

Please sign in to comment.