-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limitation on using conformed values limits usefulness of some s/and
specs
#102
Comments
Sadly, it means expound fails on the very first example of instrumentation in the official spec guide use |
Ah, good point, that's not a great experience for someone working through the official docs 😞 . Thanks for pointing that out 😄 Certainly defaulting to normal output is one option I'm considering. I'm not sure if falling back on normal But given that this more common (and, as you point out, included in the official docs), it might make sense to make falling back to normal In any case, the workaround for now is to wrap the printer in a try/catch and default to (require '[expound.alpha :as expound])
(defn safe-printer [explain-data]
(let [exp (expound/custom-printer {})]
(try
(exp explain-data)
(catch Exception e e
(s/explain-printer explain-data)))))
(set! s/*explain-out* safe-printer)
(s/def ::sorted-pair (s/and (s/cat :x int? :y int?) #(< (-> % :x) (-> % :y))))
;; Usually use expound
(s/explain int? "a")
;;-- Spec failed --------------------
;;
;; "a"
;;
;;should satisfy
;;
;; int?
;;
;;-------------------------
;;Detected 1 error
;; If there is an issue, fallback on s/explain-printer
(s/explain ::sorted-pair [0 0])
;; val: {:x 0, :y 0} fails spec: :expound.alpha/sorted-pair predicate: (< (-> % :x) (-> % :y)) |
I wonder if I could look for both the conformed and unconformed value in the original data, then show both. Something like:
I this more about this. |
@bhb I think you can rely on both conform and unform working for a "pure" However, it is of course possible that a user just mixed Generally I dont create an unform function for those cases but just put So I guess that you would need some kind of heuristics to figure out if you are able to unform the values or if you just default to the classical output. Btw, if you default to the classical output, would it be possible to still have a warning printed before it mentioning that you are getting the default output due to the unform part? otherwise the user would be left wondering if expound is actually working or not. Hope it helps |
@bhb first of all, I have to say "Thanks a lot for putting the effort of figuring this out" I tried the following cases and they all worked wonderfully. I think there are some cases where the output could be slightly more accurate but those are pretty much nice to have; here I am referring to the first case 'string parsing', where it is clear from the output that there is a single value not a collection so the text |
@carocad Thanks very much for trying it out! I appreciate it.
Yes, you're right: Expound could do more here, but since string parsing is advanced at best, and discouraged at worst, I'm not inclined to add much more here. I may change my mind in the future, but I think this is sufficient for now 😄 |
Fixed in 0.7.2-SNAPSHOT (to be released soon) |
Expound doesn't support using conformers to coerce values, because it significantly complicates the way Expound highlights the bad value (Expound uses a bunch of heurisitics to try to disambiguate the information returned by
explain-data
and these heuristics rely on the original unconformed value appearing the larger structure).However, this restriction means that Expound can't print error messages for some
and
specs, sinceand
conforms the values.The text was updated successfully, but these errors were encountered: