r/Clojure • • Dec 18 '18

Clojure 1.10 error messages

http://insideclojure.org/2018/12/17/errors/
92 Upvotes

23 comments sorted by

View all comments

2

u/xtreak Dec 19 '18

Thanks a lot for this /u/alexdmiller . Can the value be printed along with the exception in some cases like below

Current error on 1.10

(map identity (map 123 (range 10)))
Error printing return value (ClassCastException) at clojure.core/map$fn (core.clj:2753).
java.lang.Long cannot be cast to clojure.lang.IFn

Adding the value that cannot be cast might give better context

(map identity (map 123 (range 10)))
Error printing return value (ClassCastException) at clojure.core/map$fn (core.clj:2753).
java.lang.Long (123) cannot be cast to clojure.lang.IFn

3

u/alexdmiller Dec 19 '18

The error message phase here is in printing the return value. So it can’t be printed, because that is where the error occurs. A lot of lazy sequence errors end up looking like this.

This particular error is a case where the invocation is wrong (args swapped), which is really a perfect case for a spec or precondition, to avoid constructing a broken lazy seq. I’ve been thinking we should probably improve the particular “can’t cast to IFn” too since it’s so common.

1

u/xtreak Dec 19 '18

Thanks for the reply. I guess there had been attempts to spec clojure's core functions but they were abandoned due to various reasons. I would love to see upcoming improvements.

2

u/alexdmiller Dec 19 '18

https://github.com/slipset/speculative is ok and has a spec that would catch this.

1

u/xtreak Dec 19 '18

Thanks!