Comments (5)
Thanks very much for reporting this bug!
This is a tricky one to solve in general.
A little context: Expound uses the data returned by explain-data
to print an error message.
This "explain-data" contains a "value" (which is the top-level form) and a sequence of problems, each of which contains (among other things) a "val" (which points to the bad value) and an "in" (which is the path to the bad value). For example:
(require '[clojure.spec.alpha :as s])
(s/explain-data (s/coll-of int?) [1 2 :a])
;; explain-data is:
;; #:clojure.spec.alpha{:problems ({:path [], :pred int?, :val :a, :via [], :in [2]}), :spec #object[clojure.spec.alpha$every_impl$reify__934 0xdfe0a61 "clojure.spec.alpha$every_impl$reify__934@dfe0a61"], :value [1 2 :a]}
In this example, there is just one "problem". The value is [1 2 :a]
, the val is :a
and the :in
is [2]
.
In this simple case, the :in
path is easy to interpret. However, in general, there are cases where it's tricky to figure out how to interpret the :in
path - see https://dev.clojure.org/jira/browse/CLJ-2192
Expound has a lot of code dedicated to figuring out the :in
path. One heuristic I use is that the :val
should be located somewhere within the :value
(that is, the part of the data that is invalid should exist within the top-level form).
However, in the case of fspec
failures, this assumption is not true - see https://dev.clojure.org/jira/browse/CLJ-2258
As a result, we get this bug - Expound can't figure out how to interpret the :in
path and crashes.
My first impression is that it's not possible to solve this in general until one or both of the above Jira issues are fixed. However, there may be a way to solve this in at least some cases. I'll think more about this.
from expound.
@athos I've released version 0.3.3 which contains this fix. Thanks for your help!
from expound.
@athos Thanks again for reporting this! I don't think it's possible to fix this in every case, but I think I have a heuristic for the more common cases. Can you try out 0.3.3-SNAPSHOT
and see if it works in your case?
from expound.
Thank you for the quick reply and polite explanation about the context.
I'm a little bit familiar with those things since I'm also working on a library similar to Expound (named Pinpointer) for more than a year 😃
I looked into the issue today, and now I see the difficulty of giving a general solution to it. In general, a return value generated by a fspec
could not be mapped into the input value, which is a very similar situation where a conformer
transforms the input value.
So, yeah, I think your new PR now resolves the issue to some extent, and it would be sufficient for practical problems IMHO.
from expound.
I'm a little bit familiar with those things since I'm also working on a library similar to Expound (named Pinpointer) for more than a year
Excellent! I took a quick look at Pinpointer and it looks great! I'll look take a look at Jira issues you've opened for spec and vote them up. Anything that makes it easier to build something like Expound or Pinpointer helps everyone :)
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.