This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-06
Channels
- # bangalore-clj (2)
- # beginners (24)
- # boot (18)
- # cider (21)
- # cljs-dev (11)
- # clojars (3)
- # clojure (99)
- # clojure-brasil (1)
- # clojure-dusseldorf (2)
- # clojure-france (9)
- # clojure-greece (3)
- # clojure-russia (1)
- # clojure-spec (5)
- # clojure-uk (5)
- # clojurescript (205)
- # core-logic (2)
- # cursive (24)
- # datomic (13)
- # figwheel (1)
- # gsoc (1)
- # jobs (1)
- # jobs-discuss (7)
- # lambdaisland (5)
- # leiningen (4)
- # om (2)
- # pedestal (2)
- # proton (2)
- # re-frame (7)
- # reagent (5)
When using spec/explain
on a spec which contains spec/coll-of
in cljs and passing in an invalid datastructure, I don't seem to be getting any information about the offending element of the coll, only that something is wrong within the coll. Example:
(spec/explain (spec/coll-of string? []) ["hey" "yo" 9])
val: ["hey" "yo" 9] fails predicate: (coll-checker string?)
For contrast, here is the ouput for a Schema validation similar to the spec explain:
(schema/validate [schema/Str] ["hej" "yo" 9])
#error {:message "Value does not match schema: [nil nil (not (cljs$core$string? 9))]", :data {:type :schema.core/error, :schema [<#C1923ED97|schema>.core.Predicate{:p? #object[cljs$core$string_QMARK_ "function cljs$core$string_QMARK_(x){
Can I do something to make Spec give me more detailed output, similar to that of Schema?
In my actual use case, the spec/coll-of
contains more complex maps with nested specs, and if one thing goes wrong somewhere in the coll-of
, I'm left in the dark, fumbling for the specifics.@mobileink: here's a more elaborate example of what I mean in regards to Schema providing more information than Spec, leaving me desiring more from Spec. Spec:
(spec/def ::id int?)
(spec/def ::name string?)
(spec/def ::person (s/keys :req-un [::id
::name]))
(spec/explain (spec/coll-of ::person []) [{:id 1 :name "john"} {:id 2 :name :heather}])
val: [{:id 1, :name "john"} {:id 2, :name :heather}] fails predicate: (coll-checker :sleepydo.db/person)
;; No information about _which_ element of the coll failed to validate, nor details about how it failed to validate
Schema:
(def Id schema/Int)
(def Name schema/Str)
(def Person {:id Id
:name Name})
(schema/validate [Person] [{:id 1 :name "john"} {:id 2 :name :heather}])
#error {:message "Value does not match schema: [nil {:name (not (cljs$core$string? :heather))}]", :data {:type :schema.core/error, :schema [{:id <#C1923ED97|schema>.core.Predicate{:p? #object[cljs$core$integer_QMARK_ "function cljs$core$integer_QMARK_(n){
...
;; Information about which element of the coll failed to validate, as well as the offending value and its predicate function.
Does s/with-gen
take a thunk that returns a generator for laziness? Is that way it doesn’t just take a generator directly?
@mobileink: here's a more elaborate example of what I mean in regards to Schema providing more information than Spec, leaving me desiring more from Spec. Spec:
(spec/def ::id int?)
(spec/def ::name string?)
(spec/def ::person (s/keys :req-un [::id
::name]))
(spec/explain (spec/coll-of ::person []) [{:id 1 :name "john"} {:id 2 :name :heather}])
val: [{:id 1, :name "john"} {:id 2, :name :heather}] fails predicate: (coll-checker :sleepydo.db/person)
;; No information about _which_ element of the coll failed to validate, nor details about how it failed to validate
Schema:
(def Id schema/Int)
(def Name schema/Str)
(def Person {:id Id
:name Name})
(schema/validate [Person] [{:id 1 :name "john"} {:id 2 :name :heather}])
#error {:message "Value does not match schema: [nil {:name (not (cljs$core$string? :heather))}]", :data {:type :schema.core/error, :schema [{:id <#C1923ED97|schema>.core.Predicate{:p? #object[cljs$core$integer_QMARK_ "function cljs$core$integer_QMARK_(n){
...
;; Information about which element of the coll failed to validate, as well as the offending value and its predicate function.