Skip to content

Commit

Permalink
Improve error messages + labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Apr 9, 2017
1 parent 5621140 commit 34b5de1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/taoensso/truss.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions src/taoensso/truss/impl.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -169,8 +169,8 @@
undefn-val? (instance? WrappedError val)
val-str
(cond
undefn-val? "<undefined>"
(nil? val) "<nil>"
undefn-val? "<truss/undefined-val>"
(nil? val) "<truss/nil>"
:else
#_(str val)
#_(pr-str val)
Expand All @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 34b5de1

Please sign in to comment.