[spec] "caller" information missing in explain-data during macro instrumentation failure
Description
Environment
org.clojure/spec.alpha "0.1.143"
Activity
Alex MillerNovember 26, 2018 at 12:49 PM
I’d hate to make this something only useable by the clojure main repl tgough - would be better to happen always if using some other repl, so would be better to do at construction. I have a better handle on how to do so now, but don’t know if it’s too late for 1.10.
Ben BrinckerhoffNovember 25, 2018 at 11:53 PM
With the recent error message work (great work!) the symbol appears to be available, but it not currently passed to the "explain-out" function: https://github.com/clojure/clojure/blob/b182982007df934394f0bc68b3a238ca9f200dd1/src/clj/clojure/main.clj#L268-L279
Would it be possible to "assoc" this into the "spec" passed to "spec/explain-out"? This would allow custom printers to refer to the name of the spec, which would be very useful.
An alternative approach would be for users to set up custom error handlers in the REPL, but this is much more involved than setting up a third-party implementation of "explain-out"
Alex MillerAugust 22, 2018 at 4:34 PM
The issue here is that at the point where the macro spec error is created, we don't have any way to know the proper caller information. The stack at that point is the compiler macroexpansion, not the invoking code. macroexpansion does know that context and that's what it adds when wrapping with a CompilerException (that's the primary purpose of CompilerException).
I think to change that we would need to convey that info out of band into the spec check. Well, maybe that's possible. I'll look at it again.
Ben BrinckerhoffAugust 22, 2018 at 4:02 PM
I'm glad to hear this will be included in the CompilerException, but I think it still is useful to include in the spec explain-data.
When printing a spec error, it would be clearer if macro expansion spec errors and instrumentation errors could be printed in a similar format (if the user chooses a custom spec printer). It may be disruptive to look for the caller information in one place for macro expansion errors and a different place for instrumentation errors.
Furthermore, spec printers may choose to do novel things with this caller information like adding color to output or printing the actual code instead of the line numbers. It'd be nice to do have all this information available for the spec printer to customize.
Alex MillerAugust 22, 2018 at 3:44 PM
After CLJ-2373, the caller information for spec macro failures will be conveyed in a wrapper CompilerException (as with other compiler and macroexpansion errors). Should consider whether this issue is effectively resolved as a result.
Details
Assignee
UnassignedUnassignedReporter
Ben BrinckerhoffBen BrinckerhoffLabels
Approval
TriagedPriority
MajorAffects versions
Details
Details
Assignee
Reporter
Labels
Approval
Priority

When there is a instrumentation failure for a function, the explain-data includes "caller" information. However, this information is missing if the instrumentation failure is for a macro.
This comment has led me to believe that the intended behavior is for explain-data to contain this info, so third-party error printers can display it.
In the repro below, I'm setting up a custom printer just to capture the raw explain-data (it's not a useful printer, just a means to show what is happenening)
Repro: