nrepl

borkdude 2022-08-11T17:02:26.960269Z

Does nREPL have something for displaying stacktraces, e.g. by sending over stack trace data? Right now the stacktrace with babashka + CIDER isn't very useful, but bb does have useful data that it could send to the client

borkdude 2022-08-11T17:08:07.144629Z

This is how the exception now displays. The ex-data contains the interpreter stacktrace

borkdude 2022-08-11T17:08:34.775179Z

cc @bozhidar

bozhidar 2022-08-12T07:23:53.808409Z

The only built-in facility currently is ex-info. cider-nrepl has an additional stracktrace middleware that can display structured stack traces, though. Both ex-info and stacktrace predate the addition of the rich ex-data that was added around Clojure 1.10 if I recall correctly.

borkdude 2022-08-12T07:25:03.970539Z

ex-data the function in clojure or is this something in nREPL?

borkdude 2022-08-12T07:25:36.912839Z

@bozhidar Let's start with the most simple thing though: how do I communicate the file, line and column of an error to an nREPL client in 2022?

borkdude 2022-08-12T07:25:45.505939Z

That already doesn't work properly for bb

bozhidar 2022-08-12T07:36:04.125749Z

Out of the box currently you can only supply an exception class and an error message for the failed eval:

(<--
  id         "25"
  session    "bdae3a62-a52e-46d4-959a-4ea1f6d1a735"
  time-stamp "2022-08-12 09:31:02.571684633"
  err        "ArithmeticException Divide by zero  clojure.lang.Numbers.divide (Numbers.java:158)
"
)
(<--
  id         "25"
  session    "bdae3a62-a52e-46d4-959a-4ea1f6d1a735"
  time-stamp "2022-08-12 09:31:02.574206251"
  ex         "class java.lang.ArithmeticException"
  root-ex    "class java.lang.ArithmeticException"
  status     ("eval-error")
)

bozhidar 2022-08-12T07:36:47.851109Z

The expectation is that clients will parse the err message and extract the filename and the location from it.

bozhidar 2022-08-12T07:38:27.295989Z

Probably it'd be nice if we made this more flexible and made it possible to return the map with exception metadata as well, so newer clients would use it instead. (e.g. there could ex-data is the second eval-error message)

borkdude 2022-08-12T07:39:16.258709Z

The thing I'd be interested in is have a data-driven way to make CIDER highlight the error in the right location in the babashka script

borkdude 2022-08-12T07:39:29.647199Z

This info is normally not on the ex-data

bozhidar 2022-08-12T07:41:21.477519Z

CIDER parses the err message (using a regular expression) and uses it to highlight an entire line as the cause of the exception. In the presence of the stacktrace middleware it gets more precise data from it.

borkdude 2022-08-12T07:41:55.925239Z

So if bb.nrepl printed the error in this format, it should work. I'll give that a try

borkdude 2022-08-12T07:42:59.907539Z

hmm wait

borkdude 2022-08-12T07:43:19.049519Z

in ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:158) there is no reference to the user's clojure file where the error happened

borkdude 2022-08-12T07:43:26.228939Z

so how is that going to work

bozhidar 2022-08-12T07:50:04.609849Z

Bad example I guess - for most exceptions there's actually file in which the exception was raised. Probably / is defined in Numbers.java.

bozhidar 2022-08-12T07:50:58.035779Z

Perhaps nREPL can work harder to find the most relevant frame of the stacktrace - I guess that was the top frame and that's what we use by default. I haven't looked at this code in ages, so I don't remember well how it works at this point.

bozhidar 2022-08-12T07:53:27.493609Z

Some examples from the tests in CIDER how we use this https://github.com/clojure-emacs/cider/blob/65a23e54227e3575f5a909dcfbdbbaef70d1438b/test/cider-error-parsing-tests.el