From 34b5de13b6c5072f6ec1b7a7e91e5ad814f92cad Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sun, 9 Apr 2017 22:08:23 +0200 Subject: [PATCH] Improve error messages + labels --- src/taoensso/truss.cljx | 2 ++ src/taoensso/truss/impl.cljx | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/taoensso/truss.cljx b/src/taoensso/truss.cljx index fd0a974..7e744ba 100644 --- a/src/taoensso/truss.cljx +++ b/src/taoensso/truss.cljx @@ -64,6 +64,8 @@ (have number? (do (println "eval1") 5) (do (println "eval2") "bar") (do (println "eval3") 10)) + (have pos? "hello") + (have pos? (/ 1 0)) (have nil? false) (have nil) (have false) diff --git a/src/taoensso/truss/impl.cljx b/src/taoensso/truss/impl.cljx index cc4699f..04f2cf3 100644 --- a/src/taoensso/truss/impl.cljx +++ b/src/taoensso/truss/impl.cljx @@ -142,7 +142,7 @@ (defn- fmt-err-msg [x1 x2 x3 x4] ;; Cider unfortunately doesn't seem to print newlines in errors - (str "Invariant violation in `" x1 ":" x2 "`. Test form `" x3 "` with failing input: `" x4 "`")) + (str "Invariant violation in `" x1 ":" x2 "`. Test form `" x3 "` failed against input val `" x4 "`.")) #+clj (defn- fast-pr-str @@ -169,8 +169,8 @@ undefn-val? (instance? WrappedError val) val-str (cond - undefn-val? "" - (nil? val) "" + undefn-val? "" + (nil? val) "" :else #_(str val) #_(pr-str val) @@ -192,8 +192,8 @@ msg (fmt-err-msg ns-str line-str form-str val-str)] (cond (not ?err) msg - undefn-val? (str msg "\n`val` error: " ?err-str) - :else (str msg "\n`pred-form` error: " ?err-str)))) + undefn-val? (str msg " An error was thrown while evaluating input val: [" ?err-str "].") + :else (str msg " An error was thrown while evaluating test form: [" ?err-str "].")))) ?data (when-let [data-fn ?data-fn] @@ -206,8 +206,8 @@ :?line ?line ;; :?form (when-not (string? form) form) :form-str form-str - :val (if undefn-val? 'undefined/threw-error val) - :val-type (if undefn-val? 'undefined/threw-error (type val)) + :val (if undefn-val? 'truss/undefined-val val) + :val-type (if undefn-val? 'truss/undefined-val (type val)) :?data ?data ; Arbitrary user data, handy for debugging :*?data* *?data* ; '' :?err ?err