Enhance CompilerException to optionally return the invalid form

Description

Currently CompilerException wraps errors that occur at compile time and adds file/line/col info. Some tools could do more with the failing form, particularly if it includes useful meta.

Proposal is to add a CompilerException constructor that also takes the form (Object) and conveys it. Existing uses like CLI and REPL would do nothing different, but a tooling user of the Compiler could use that information.

Possible issue: if the form is lazy or large?

Environment

None

Activity

Thomas Heller 
March 16, 2017 at 8:00 PM

I added the current reader location to the Compiler Exception [1].

This would at least allow extracting the entire source string of the form easily. When using a reader however it could start at the location already provided by the CompilerException and it would find the end on its own. The bindings required for the reader location are also lost when working in a REPL, so it always points to 0/0-0/0. Not sure this is worth pursuing.

[1] https://github.com/clojure/clojure/compare/master...thheller:CLJ-2128

Thomas Heller 
March 16, 2017 at 6:37 PM

Looking into LINE_BEFORE, COLUMN_BEFORE, LINE_AFTER, COLUMN_AFTER now to potentially provide the exact boundaries of the form if possible.

Thomas Heller 
March 16, 2017 at 6:29 PM

I added the latest form to the CompilerException when available but that form contains basically no metadata.

That information is already present in the CompilerException. Having the form provides minimal benefit in this case since it has lost all other source information and we cannot tell how this look in the the source. To get a source mapping for tools so they can highlight the correct area it would still need to read the form itself (and probably not using the form from the Exception).

Declined

Details

Assignee

Reporter

Approval

Priority

Created March 16, 2017 at 3:41 PM
Updated August 22, 2018 at 3:36 PM
Resolved August 22, 2018 at 3:36 PM