Welcome! Please see the About page for a little more info on how this works.

0 votes
in Spec by

Using s/assert instead of assert has advantages: namely a specific reason why the data failed to meet the spec. But it also has disadvantages: the error message does not contain the assertion code the user wrote, so it's harder to see which assertion failed.

I believe we could have the best of both world if s/assert contained the original "assert" code - that way the error message could (optionally) print out this information.

(require '[clojure.spec.alpha :as s])
(s/check-asserts true)

(let [x 1]

(s/assert string? x))

;; Spec assertion failed val: 1 fails predicate:
;; :clojure.spec.alpha/unknown

(let [x 1]

(assert (string? x)))

;; Assert failed: (string? x)

1 Answer

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-2273 (reported by bbrinck)