[racket-dev] Changing the default error display handler to use exn:srclocs

From: Eric Dobson (eric.n.dobson at gmail.com)
Date: Wed Mar 12 21:05:03 EDT 2014

A common issue I have is that the default error handler does not
display error message's exn:srcloc if it has it

racket -e "(require racket/match)" -e "(match 2)"
=>
match: no matching clause for 2
  context...:
   /Users/endobson/proj/rnacket/plt/racket/collects/racket/match/runtime.rkt:21:0:
match:error

But no information about what match raised the issue. The handler in
DrRacket uses this info nicely in the buttons that it provides and the
highlighting.

Is this reasonable to add to the default error handler, and if so do
people have suggestions on the format?


My current .racketrc has

 (let ((old-error-display-handler (error-display-handler)))
    (error-display-handler
      (λ (str exn)
        (when (exn:srclocs? exn)
          (for ((srcloc ((exn:srclocs-accessor exn) exn)))
            (displayln (source-location->string srcloc))))
        (old-error-display-handler str exn)))))

Which is a hack but works for my interactive use. It doesn't work for
when I run a program on its own, and I don't see a way to configure
anything to do that.


Posted on the dev mailing list.