From f42b81b88e862972b2f5e55a215b6e2851f96a97 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Mon, 31 Jul 2023 11:50:07 +0200 Subject: [PATCH] [mod] Improve invariant violation output 1. Message: show (pred arg-form) rather than (pred arg-value) 2. Message: include column info 3. Data: pred value now shows resolved pred symbol when pred-form is a symbol --- src/taoensso/truss/impl.cljc | 6 +++--- test/taoensso/truss_tests.cljc | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/taoensso/truss/impl.cljc b/src/taoensso/truss/impl.cljc index 8ac4d83..3877ef0 100644 --- a/src/taoensso/truss/impl.cljc +++ b/src/taoensso/truss/impl.cljc @@ -264,8 +264,8 @@ (let [;arg-form (if (nil? arg-form) 'nil arg-form) msg (str "Invariant failed at " ns-sym - (when ?line (str "|" ?line #_(when ?column (str "." ?column)))) ": " - (list pred-form #_arg-form arg-val))] + (when ?line (str "[" ?line (when ?column (str "," ?column)) "]")) ": " + (list pred-form arg-form #_arg-val))] (if-let [err ?err] (let [err-msg #_(ex-message err) (error-message err)] @@ -292,7 +292,7 @@ output {:msg_ msg_ :dt instant - :pred pred-form + :pred (or pred-rsym pred-form) :arg {:form arg-form :value arg-val :type arg-type} diff --git a/test/taoensso/truss_tests.cljc b/test/taoensso/truss_tests.cljc index 47272e7..52eaab3 100644 --- a/test/taoensso/truss_tests.cljc +++ b/test/taoensso/truss_tests.cljc @@ -142,7 +142,18 @@ [(is (= "5" (have string? "5"))) (is (throws? :common {:data {:dynamic {:user 101}}} (have string? 5))) (is (throws? :common {:data {:dynamic {:user 101} - :arg {:name "Stu"}}} (have string? 5 :data {:name "Stu"})))])])]) + :arg {:name "Stu"}}} (have string? 5 :data {:name "Stu"})))])]) + + (testing "Resolved preds" + [(is (throws? :common {:pred 'taoensso.truss-tests/my-pred} (have my-pred false))) + + (is (throws? :common {:pred #?(:clj 'clojure.core/some? + :cljs 'cljs.core/some?)} (have nil))) + + (is (throws? :common {:pred #?(:clj 'clojure.core/string? + :cljs 'cljs.core/string?)} (have string? nil))) + + (is (throws? :common {:pred '[:or string?]} (have [:or string?] nil)))])]) ;;;;