“Pretty” does a great job of cleaning up stack traces as a Leiningen plugin. Is there a way I can have the behavior injected for a deps.edn project?
$ clj -Sdeps '{:deps {io.aviso/pretty {:mvn/version "0.1.37"}}}'
Clojure 1.10.0
user=> (use 'io.aviso.repl)
nil
user=> (install-pretty-exceptions)
nil
user=> (/ 1 0)
Execution error (ArithmeticException) at user/eval744 (REPL:1).
Divide by zero
user=> (pst)
clojure.core/eval core.clj: 3214
...
user$eval744.invoke NO_SOURCE_FILE: 1
user$eval744.invokeStatic NO_SOURCE_FILE: 1
...
java.lang.ArithmeticException: Divide by zero
nil
Hi Alex! Thank you. Is there a concept of injections or middleware in ~/.clojure/deps.edn? that would activate this?
No, nothing like this. clj just runs clojure.main, which is just a program runner, so there are a variety of ways to have it run programs around your repl (which is of course, also just a program) if you like.
For example, you could create a script that injects pretty, then starts the repl:
$ cat myrepl.clj
((requiring-resolve 'io.aviso.repl/install-pretty-exceptions))
(clojure.main/main)
Then create a deps.edn with an alias that includes pretty and runs the script (this and the prior file could also be in your ~/.clojure dir, becoming available to all deps.edn projects):
$ cat deps.edn
{:aliases
{:myrepl {:extra-deps {io.aviso/pretty {:mvn/version "0.1.37"}}
:main-opts ["myrepl.clj"]}}}
Then start clj with your alias:
$ clj -A:myrepl
Clojure 1.10.0
user=> (/ 1 0)
java.lang.ArithmeticException: Divide by zero
user=> (pst)
clojure.core/eval core.clj: 3214
...
user/eval744 myrepl.clj: 1
...
java.lang.ArithmeticException: Divide by zero
There are of course an infinite number of ways to install/configure/start/prep your repl but you have full program-making capability at your fingertips.
You can also check out https://github.com/mbuczko/revolt. I’ve found it to be pretty useful for this type of situation, as you can create your own plugins and tasks and then load them using deps.edn aliases.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.