Skip to content
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

When expound can't print error (due to conformers), print vanilla spec error #78

Closed
bhb opened this issue Mar 28, 2018 · 9 comments
Closed

Comments

@bhb
Copy link
Owner

bhb commented Mar 28, 2018

No description provided.

@bhb
Copy link
Owner Author

bhb commented Jun 23, 2018

Related: #102

@bhb
Copy link
Owner Author

bhb commented Jun 23, 2018

Workaround:

(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))

@arichiardi
Copy link
Contributor

I have run into this and thanks for the workaround!

@bhb
Copy link
Owner Author

bhb commented Oct 26, 2018

@arichiardi @borkdude I've got a fix for this issue in 0.7.2-SNAPSHOT. If you have time to try it out, please let me know what you think!

@arichiardi
Copy link
Contributor

First feedback, with shadow-cljs I receive these warnings:

------ WARNING #1 --------------------------------------------------------------
 File: expound/problems.cljc:110:47
--------------------------------------------------------------------------------
 107 |                         :clj java.lang.Exception) _e
 108 |                 nil)
 109 |               (catch #?(:cljs :default
 110 |                         :clj java.lang.Error) _e
-----------------------------------------------------^--------------------------
 Use of undeclared Var expound.problems/_e
--------------------------------------------------------------------------------
 111 |                 nil))
 112 | 
 113 |         new-in (cond in1
 114 |                      in1
--------------------------------------------------------------------------------

@bhb
Copy link
Owner Author

bhb commented Oct 27, 2018

Good catch! I've added a new check for warnings to the CI script and fixed this warning. I've pushed a new version of 0.7.2-SNAPSHOT with the fix.

@borkdude
Copy link

@bhb Is this also available in master?

I've tried http://bit.ly/speculative-repl with

(stest/instrument `subs)
(try
  ;; insert your call here
  (subs "foo" 5)
  (catch :default e
    (println (.-message e))
    (throw e)))

and I'm seeing:

Cannot convert path. This can be caused by using conformers to transform values, which is not supported in Expound

@bhb
Copy link
Owner Author

bhb commented Nov 16, 2018

This is currently only on the “next” branch. I’m hoping to get a release out this month, which will move this to master.

@bhb
Copy link
Owner Author

bhb commented Dec 13, 2018

Fixed in 0.7.2-SNAPSHOT (to be released soon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants