Fork me on GitHub
#nrepl
<
2022-08-11
>
borkdude17:08:26

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

borkdude17:08:07

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

bozhidar07:08:53

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.

borkdude07:08:03

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

borkdude07:08:36

@U051BLM8F 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?

borkdude07:08:45

That already doesn't work properly for bb

bozhidar07:08:04

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")
)

bozhidar07:08:47

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

bozhidar07:08:27

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)

borkdude07:08:16

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

borkdude07:08:29

This info is normally not on the ex-data

bozhidar07:08:21

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.

borkdude07:08:55

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

borkdude07:08:19

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

borkdude07:08:26

so how is that going to work

bozhidar07:08:04

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

bozhidar07:08:58

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.