-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Alex:
c.c/count, RT.countFrom previously did not report the full name of a
class on which counting is not supported.
c.c/cons, RT.cons previously generated
> IllegalArgumentException Don't know how to create ISeq from:
java.lang.Object clojure.lang.RT.seqFrom (RT.java:528)
now generates
> IllegalArgumentException cons needs a sequable, got
> java.lang.Object
c.c/{first,second,third,fourth,next,more} and corresponding RT methods
previously generated
> IllegalArgumentException Don't know how to create ISeq from:
java.lang.Object
sourced typically from either RT.seq or RT.seqFrom. Now generates
> IllegalArgumentException $METHOD needs a sequable, got
> java.lang.Object
for $METHOD as appropriate.
On c.c/{pop,assoc,dissoc} or rather the corresponding methods there
are actually breaking changes. Previously raw ClassCastExceptions
would be generated, now IllegalArgumentExceptions are generated.
Previously
> ClassCastException java.lang.Object cannot be cast to
clojure.lang.Associative
now generates
> IllegalArgumentException assoc needs an associative, got
java.lang.Object
Similarly c.c/find, RT.find previously
> ClassCastException java.lang.Object cannot be cast to
> java.util.Map
now generates
> IllegalArgumentException find needs a map or associative, got a
java.lang.Object
As hinted below, maybe nested exceptions would be a better way to
model this without loosing information, but the idea is that if we
take this approach and extend it, we can add some more useful bits of
information at every level of the call stack by adding similar
reporting into clojure.core and then maybe we can get somewhere.
Nicola:
Yes that is precisely the point. These changes won't meaningfully help
anyone reading this list now, and nor were they intended to. You or I
can look up in the source if we don't just remember what's going on,
but that's an expectation I don't think we can or should have of
newcomers. Looking up Associative or some other interface they'll find
what is officially an undocumented implementation detail or a bunch of
StackOverflow posts explaining how this cryptic error message relates
to what it is they thought they were doing. The point of this sketch
is not that it makes a huge UX improvement, but that it does
_something_ which could be expanded upon.
Maybe it would be better to throw exceptions with causes rather than
masking nested exceptions as this patch does. Maybe there's more we
can say in error messages. That's why I started this thread instead of
whining and disappearing into background radiation.
In response to your performance concerns on twitter, if you can come
up with something more useful or show how to achieve anything along
these lines more efficiently than by using the existing exception
infrastructure I welcome the lesson. This is the best prototype in
both those dimensions which I could devise for the purpose of starting
a discussion on better errors.
Reid