borkdude/spartan.spec

Using `s/cat` nested within `s/or` or `s/and` does not yield correct `explain-data`

Closed this issue · 2 comments

bhb commented

Version: 2c6397e

Repro

Run the following in bb repro1.clj

;; repro1.clj
(require '[babashka.deps :as deps])

(deps/add-deps
 '{:deps {borkdude/spartan.spec {:git/url "https://github.com/borkdude/spartan.spec"
                                 :sha "2c6397e0f545e58a8b14d8aa45814f79d3946dc7"}}})

(require '[spartan.spec]
         '[clojure.spec.alpha :as s]
         '[clojure.pprint :as pp])

;; pprint is not necessary to repro, but makes it easier to parse result
(pp/pprint (s/explain-data
            (s/and (s/cat :x1 int?)
                   vector?)
            ["foo"]))

Compare this with the output from a similar Clojure script: clj -M repro2.clj

;; repro2.clj
(ns repro
  (:require [clojure.spec.alpha :as s]
            [clojure.pprint :as pp]
            ))

(pp/pprint (s/explain-data
            (s/and (s/cat :x int?)
                   vector?)
            ["foo"]))

Expected: The first and only "problem" in the explain-data should be

{:path [:x],
 :pred clojure.core/int?,
 :val "foo",
 :via [],
 :in [0]}

Actual: The first and only "problem" in the explain-data is

{:path [],
 :pred (clojure.spec.alpha/cat :x1 clojure.core/int?),
 :via [],
 :val ["foo"],
 :in []}

The difference in path and pred makes it harder to print helpful error messages in Expound.

Thanks! Will look into it.

@bhb Fixed with 0babad3