Set file and line-number information in stack trace entries

Clojure has some beautiful stack trace output, to be sure, but there is a missing piece I’m wondering if someone can help with. I am (very very slowly) working on a templating system called Ash Ra Template; compiler error stack traces caused by templates currently don’t indicate the origin of errors.

I have ART to the point where you can include partials and yield blocks, a layered approach that enables you to structure your project files. For example, an HTML page might ask to have itself wrapped in the project layout HTML page template, which is in turn wrapped in the company-wide standard HTML page layout template. Your HTML page might also include several standardized parts into itself, such as the site-nav component near the top of the page, some callouts, and the standardized footer near the bottom of the page. Plenty of potential for deep stack traces and quizzical output.

When the Clojure compiler reports an error, it might occur somewhere deep in the layered templates, and the question is: where exactly? Let’s take a typical stack trace say 100 lines deep:

:trace
 [[vivid_art_user_18357$eval18422 invokeStatic nil 66]
  [vivid_art_user_18357$eval18422 invoke nil 65]
  [clojure.lang.Compiler eval "Compiler.java" 7201]
  ...
  [clojure.core$load_string invoke "core.clj" 4091]
  [vivid.art.evaluate$evaluate invokeStatic "evaluate.clj" 21]
  ...
  [clojure.lang.RestFn invoke "RestFn.java" 439]
  [vivid_art_user_18319$eval18350 invokeStatic nil 22]
  ...

and so on, instigated several layers deep in an ART template render. Ouch. Skimming over the stack trace, every file has a filename and a line number, except for the ART templates, which are nil and carry an essentially wrong line number, respectively:

  [vivid_art_user_18357$eval18422 invoke nil 65]

ART’s entries would be more useful if they read as:

  [vivid_art_user_18357$eval18422 invoke "page-layout.html.art" 41]

Here, the nil filename is replaced with the ART template’s filename. And the line number is the originating line number in the ART template file that precipitated the compiler’s outburst. This improvement alone gives a template author plenty of info to zero in on the cause.

ART templates are processed in 4 stages: :parse to a token stream, :translate, :enscript writes out a Clojure source file, :evaluate (evals) that source file to produce final rendered output. It would be of immense help to the user if the source file name and line numbers were carried from the reading of the ART template file and through those 4 stages so that Clojure’s (eval) will report a filename and line number associated in the original ART template file. This way, template authors can immediately navigate to and inspect the problem. How can this be achieved?

I have noted clojure.lang.LineNumberingPushbackReader, but the filename & line number metadata needs to be carried through those 4 phases.

Thanks!