r/Clojure • • Dec 18 '18

Clojure 1.10 error messages

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

23 comments sorted by

3

u/stingraycharles Dec 18 '18

I haven't got the chance to try 1.10 yet, but I wonder whether the new error messages also work with tools.namespace-style "refresh-all" ?

2

u/alexdmiller Dec 18 '18

Not sure what you mean? Things that previously threw exceptions should continue to do so, but with more data and (if at the repl) better messages.

2

u/stingraycharles Dec 18 '18

I typically use refresh-all to reload my code; since the examples are all very much focused on everything in an isolated REPL session without loading files. I was wondering whether these error improvements will also we available when code is evaluated using `require` or `refresh-all`.

2

u/alexdmiller Dec 18 '18

Certainly, if you are doing 'require' at the REPL, you will see the same behavior (except locations will be at "(foo.clj:10:0)" instead of "(REPL:10:0)"). So, I believe you should see things as expected. But try it and see!

3

u/stingraycharles Dec 18 '18

That's great news, and the answer I was hoping for. I'll probably give it a try this week!

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!

23

u/aptmnt_ Dec 18 '18

The change from calling out some place in the clojure implementation to calling out where in your code or repl something went wrong is a huge usability win. Thanks for the improvements.

1

u/joequin Dec 19 '18

I quit using clojure, in part, because of how annoying that was. I honestly can't believe it took this long.

3

u/aptmnt_ Dec 19 '18

Hope this change entices you back!

4

u/joequin Dec 19 '18 edited Dec 19 '18

Clojure is the best dynamically typed language I've ever used, but it's still dynamically typed and for me, that's a deal breaker.

I'm still really glad I learned it as the first language I bought myself while I was in college. The lessons I learned from it have helped me when programming in any language. It taught me the value if immutability and pure functions whenever reasonable. Those principles are helpful no matter what you're working with unless you need extreme performance, which is very rare.

But I do find statically typed languages much easier to use when working with other programmers and when using libraries. It's often easier to work on a project by myself when it's statically typed. There's fewer things I have to keep track of in my head when the compiler and editor can use types to help me.

3

u/64BitChris Dec 19 '18

Have you tried spec yet? I have found it to be much more powerful than the type systems I'm familiar with (Java, Typescript, etc.)

Spec has kept me with Clojure because I agree with your points about type systems, but like I said I find spec to me much more powerful.

2

u/joequin Dec 19 '18

I haven't. It was very very early on in it's development when I stopped using clojure.

How well does it work in practice when working with popular libraries? Do they usually define specs?

2

u/64BitChris Dec 20 '18

That's a great question. It's hit or miss and I'd say a lot of the libraries I use don't have specs because they're older.

However, I usually build my own layer around calls to those libraries and I can add specs there - and then with generative testing I can through test the abstraction before sharing it with others.

12

u/totemo Dec 18 '18

Thanks for this, Alex.

8

u/therealdivs1210 Dec 18 '18

Thank you for the great error reporting!

7

u/aria4242 Dec 18 '18 edited Dec 18 '18

Really loving these Alex as I’ve been easing back into Clojure

6

u/human_without_god Dec 18 '18

Thanks rich, alex, stuart, and others! The error stuff and rebl are awesome.

5

u/TheSkepticalWhale Dec 18 '18

This is fantastic. As much as I enjoy using Stuart Halloway’s scientific method debugging strategy, these error messages make it a lot easier to zero in on the problem.

2

u/xenow Dec 19 '18

Thanks Alex and friends, this is a great update!