Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Clojure by

When a exception is thrown at macro compilation time,
the stack trace does not contain the "originating line", at least in my case.

So when I want to look "where" in my code the issue starts, the stack trace does not help.

Specially for a Clojure beginner (from a Java background), it might not be obvious that macro compilation is existing and was the reason that a stack trace does not contain "my starting line".

Quite some libraries use "macros" for "normal operations".

1 Answer

0 votes
by

Do you have an example of such a macro and the resulting exception trace?

There really isnt much the compiler can do, as it is up to the macro itself to supply source information where it can. Many macros rely on the implicit location information bound to the input of the macro, but more complex macros often should do more but do not necessarily do so.

Consider reporting problems to the macro authors, if you have reproducible cases and a macro generating code that is hard to "trace". Depending on the context it may be possible improve the debugging experience.

As an example: I have some fairly complex macros in a library I wrote and this helper (search for uses of with-loc) is responsible for transfering the necessary metadata. Without that the errors were much harder to trace back to the actual code. This is for CLJS but the basic method applies to CLJ as well.

...