Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix show function FQN in instrumentation exception #897

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2528,7 +2528,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)))))