Comments (9)
BTW I don't think this really matters in practice, though.
clojure.spec is not good at handling bare predicates in terms of error reporting while you can work around it by wrapping them with s/spec
:
=> (ex/expound (s/spec (complement str/blank?)) "")
-- Spec failed --------------------
""
should satisfy
(complement clojure.string/blank?)
-------------------------
Detected 1 error
nil
=>
It also works to just s/def
a name for the predicate:
=> (s/def ::non-blank (complement str/blank?))
:user/non-blank
=> (ex/expound ::non-blank "")
-- Spec failed --------------------
""
should satisfy
(complement clojure.string/blank?)
-- Relevant specs -------
:user/non-blank:
(clojure.core/complement clojure.string/blank?)
-------------------------
Detected 1 error
nil
=>
from expound.
@vemv Thanks for reporting this! I had noticed this as well last night, and you're right, this is really confusing! I'll work on a fix.
from expound.
@vemv Unfortunately, it turns out that we can only do a little better in this case. The slash is really confusing, but the best I can do at this point is to print out "" since spec doesn't capture the original code. Here's what it looks like in my branch (compared to the default spec output for reference):
user=> (require '[clojure.spec.alpha :as s]
#_=> '[clojure.string :as string]
#_=> '[expound.alpha :as expound])
nil
user=>
user=> (s/explain (fn [x] (not (string/blank? x))) "")
val: "" fails predicate: :clojure.spec.alpha/unknown
nil
user=> (expound/expound (fn [x] (not (string/blank? x))) "")
-- Spec failed --------------------
""
should satisfy
<anonymous function>
-------------------------
Detected 1 error
nil
from expound.
I can likely do better once https://dev.clojure.org/jira/browse/CLJ-2068 is fixed!
from expound.
Ah, nevermind:
Functions - demunge the function name and use the qualified function name symbol as the form. Add a special check for anonymous functions and revert to ::unknown for those (not much we can do with an eval'ed anonymous function).
from expound.
OK, I've just released a new version of "0.3.4-SNAPSHOT" which contains these changes (you'll need to delete your old copy in ~/.m2/repository/expound/expound
and reinstall)
from expound.
Hey there!
Thank you, much better now 🍻
Perhaps if expound/expound
was a macro, it could take the quoted predicate form as a "fallback print value" in case the predicate was unprintable?
I realise turning defns into macros is bit of a dubious move (and a breaking change). Maybe expound*
could be offered?
from expound.
@vemv Excellent, I'm glad it works.
You're correct, if expound
was a macro, I could do more. However, this might quickly get complicated. For instance, if the call to expound
was (expound/expound (s/coll-of (complement string/blank?)) [""])
, expound
would need to locate the predicate within the spec and match it with the failing predicate.
I suspect it could be done, but since wrapping the predicate in s/spec
(or defining a new named spec) seems like a pretty good workaround, I'm going to leave this for now. I may revisit it in the future if this becomes a common pain point.
Thanks for testing the fix!
from expound.
I've just released 0.3.4, which includes this bug fix.
from expound.
Related Issues (20)
- Error reports returned as :cause string in an exception when produced by instrumentation within generative testing HOT 11
- allow passing options map to expound/expound-str HOT 1
- Improve grouping of spec errors HOT 2
- Unnecessary dependency on `cider-nrepl` HOT 1
- Regression of #3 HOT 4
- Easier editing of error messages
- `printer` has invalid spec HOT 2
- "Cannot convert path" on instrumentation failures in the wild HOT 4
- (cljs.spec.test.alpha/instrument) breaks expound due to wrong arity HOT 4
- should expound work anywhere s/explain works? - clojurescript error HOT 7
- Error in :ret check when using with Orchestra 2020.07.12-1 HOT 5
- Internal error in `lift-singleton-groups` when having a datomic db value in fn args HOT 13
- Crash bug when printing, if a datomic db is present and the spec fails HOT 19
- Feature inquiry: a convenience function for validating a value against a spec HOT 4
- Wrapped `s/keys` does not properly display unqualified keyword specs HOT 5
- ClassCastException from `expound-str` when running in AWS Lambda HOT 9
- Small *print-length* and/or *print-level* sometimes yield NPE HOT 5
- PersistentList cannot be cast to class Named HOT 3
- proposal : defmsg equivalent for arbitrary predicates HOT 15
- optional include location of the spec error in the message. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expound.