Skip to content

Commit

Permalink
[mod] Improve invariant violation output
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ptaoussanis committed Jul 31, 2023
1 parent 9ff9d55 commit f42b81b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/taoensso/truss/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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}
Expand Down
13 changes: 12 additions & 1 deletion test/taoensso/truss_tests.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)))])])

;;;;

Expand Down

0 comments on commit f42b81b

Please # to comment.