Meta Redux: neorepl 0.6: Errors Made Easy (to Fix)

Wait 5 sec.

neorepl 0.6 is out!In the 0.5 post I wrote that 0.6would be about getting neorepl to more people, with Clojars, Homebrew,Windows and a documentation site. Then I started looking at what the REPLdoes when your code blows up, and, well, you can guess how that went. Thesite happened, and neorepl installs as a Clojure CLI tool now, but most ofthis release is about errors: what they mean, how to fix them, and adebugger for the ones that don’t give up easily. Hence the tagline, “Errorsmade easy (to fix)”.From error to fixEvery Clojure programmer has stared at “Unable to resolve symbol” moretimes than they’d care to admit, and nine times out of ten the fix is amissing require or a typo. The REPL knows that much, so now it tells you.When code names something that isn’t there, neorepl marks the name in whatyou typed and lists what could fix it, numbered for ,fix:user=> (join ", " ["a" "b"])Syntax error compiling at (REPL:1:1).Unable to resolve symbol: join in this context (join ", " ["a" "b"]) ^^^^ ,fix 1 (require '[clojure.set :refer [join]]) ,fix 2 (require '[clojure.string :refer [join]])user=> ,fix 2nil"a, b"The requires and imports come from cider-nrepl’s resolve-missing (orbabashka 1.13.230’s), and the fixes for typos come from completion. A fixonly ever runs when you ask for it. I stole the idea from Smalltalk’sdebugger, which offers to create the method you just called, and fromFactor and MIT Scheme, which number their restarts, but I drew the line atfixing things behind your back.The rest of the errors got some love too: An ex-info’s data shows up as fields under its message, rather than asone long map you have to squint at. A function called with the wrong number of arguments gets its arglists. The commonest errors get a line on what they tend to mean. ANullPointerException from clojure.lang.Numbers is arithmetic gettingnil, for instance. You get the line of your own code the error came from, rather than thefirst of fifty frames of clojure.lang. The first few errors point out ,pst and ,stacktrace, and the hintssetting turns all of this off, if you’d rather figure things out the hardway.Coding agents make even more typos than I do, so neorepl eval and the MCPeval tool follow such an error with the same fixes. With --format edn orjson (and in the tool’s structured content) they come as suggestions,each with the code to evaluate for it.A debugger, at lastCIDER’s debugger has been one of my favourite CIDER features ever sinceArtur Malabarba wrote it, back in 2015, and it’s the first thing I missedin neorepl. Not anymore! ,break instruments a function with cider-nrepl’sdebugger, so it stops at each step, and at each breakpoint you get CIDER’s keys:n for the next step, i and o to step in and out, c to go on, lfor the locals, e to evaluate something with them, j to return a valueof your choosing, p to inspect, q to quit and ? for everything else.A few more ways in: ,break-at FILE LINE stops at a line of a file, which also works for amethod, a function inside a def or a line in the middle of a longfunction. ,breaks lists what stops, and ,unbreak and ,unbreak-attake it out. #dbg and #break typed in front of a form work as they do in CIDER. After an error, ,debug runs the input that failed again and stops rightwhere it throws, with the locals, so you can poke around or j your waypast it. A breakpoint on a thread of its own, like an HTTP handler’s, waits with anote above the prompt until you get to it with ,stop. When the REPL exits, everything it instrumented runs as normal again, soyou don’t leave breakpoints behind that no one will ever answer.All of this works with babashka 1.13.230 as well.Bring your own editorI doubt many of you write non-trivial amounts of code straight into a REPL,so here’s what all of this looks like next to an editor:That’s Neovim, with neorepl in a :terminal split under the code, and thesetup from doc/editors.md,which is a few dozen lines of Lua and no plugin. The editor and the REPLshare a server, so whatever one of them evaluates, the other sees. Thereceipt in the REPL looks suspiciously round, so ,break format-cents anda few steps show (rem cents 10) coming back with 0. The fix in the bufferis one character, ,ee evaluates the function at the cursor (without evensaving the file), and back in the REPL the receipt finally adds up.The way I’d split the work between them: The editor evaluates things and loads files, the REPL runs them, and whensomething’s off, the REPL is where you poke at it, with the inspector,the tests, the stack traces and now the debugger. ,break-at FILE LINE is handy here, as you can put the line your cursor’son in the editor straight into it. Going the other way, ,edit NAME in the REPL opens a definition in your$EDITOR.The doc has this split too, and the same setup for Emacs, where C-M-x andC-c C-r evaluate the form at point and the region from clojure-mode, noCIDER required, and for Helix. Any terminal next to the editor will do forthe REPL, if you’d rather keep it out of the editor.So, does it feel like CIDER yet?When I announced neorepl,a lot of people didn’t understand why we needed one more terminal REPL fornREPL. Back then I said my vision was an alternative to REPLy with aCIDER-like experience in your terminal (and a good CLI for agents to leanon, if you’re into AI engineering these days). The first version of neorepldidn’t feel much like CIDER, but I hope you’ll agree that things are lookingway better in this regard now. Here’s where neorepl stands on CIDER’s majorfeatures, and what each of them needs on the server:   With cider-nrepl nREPL alone In ClojureScript Completion, arglists as you type yes yes, with nREPL 0.8 or later yes ,doc, ,source, ,where yes yes yes ,apropos yes yes Clojure’s vars only ,macroexpand yes yes yes Errors, ,pst, ,stacktrace yes yes the message, without JavaScript frames ,fix and what an error says past its message yes, requires and imports with 0.64 or later typos only no, ClojureScript only warns ,inspect yes no the value, read back as data ,test yes the namespaces you name yes ,retest yes no yes ,reload yes, and what changed the namespaces you name Clojure’s only ,autoreload yes no no ,break, ,break-at, ,debug yes no no ,trace, ,profile yes no no ,refs, ,deps yes no no ,ns and its browser yes yes yes ,spec yes yes Clojure’s specs only ,tap yes, 0.64 or later no no Like CIDER, neorepl gets the most out of cider-nrepl, which jack-in adds foryou, and the ClojureScript column assumes it’s there, through piggieback orshadow-cljs. babashka’s server, 1.13.230 or later, does everything in thefirst column but ,refs, ,deps, reloading what changed and ,tap. TheREADME has the sametable.Making the neighbours better, round four babashka’s CIDER ops now come from cider-nrepl’s own middleware, whichgave bb 1.13.230 the debugger, resolve-missing, apropos,macroexpand, the profiler and quite a bit more. I did that one myself,so it’s my fault if something’s off there. neorepl’s jack-in brings cider-nrepl 0.64.1, which fixed a couple ofproblems with reloading that neorepl used to work around. I filed a couple of cider-nrepl issues the debugger and the tests turnedup: a breakpoint waits foreveronce the client that started the debugger is gone, and tests compiledbefore the first test op report forms instead of values. The nREPL fixes are still waiting for the next nREPL release, and thepiggieback changes are still in review.Smaller things neorepl installs as a Clojure CLI tool, straight from git, withclojure -Ttools install-latest :lib io.github.nrepl/neorepl :as neorepl,and every command is a function of the tool, as in clojure -Tneorepl repl. ,apropos, neorepl apropos and the namespace browser leave out thenamespaces of nREPL, cider-nrepl and its libraries, which were mostlynoise. --tooling and the tooling setting bring them back. ,apropos fits what it lists to your terminal, and so does the profilesummary. Locations in where, refs, deps and check are relative to thedirectory you’re in, when they’re in it. Ctrl-C stops code that refuses to stop on JDK 20 and later, in theservers neorepl server starts. Each form you paste or evaluate with eval -f gets its own line andcolumn, so errors in the second form no longer point somewhere above it.neorepl also has a site now, where youcan see all of the above in action, if you’d rather not take my word for it.What’s nextClojars, an uberjar and Homebrew are still at the top of my list, alongwith proper Windows support and the frames of ClojureScript errors (whichhave been “next” since 0.2, I know). After that comes 1.0, where the CLI’sexit codes, its edn and JSON output and the MCP tools become a contract Ipromise to keep.Try it$ bbin install io.github.nrepl/neorepl$ cd my-project$ neoreplThe CHANGELOG haseverything I skipped here, and the READMEhas the details. Please keep the issues and ideas coming!That’s all I have for you today. With 0.6 out, I feel we’re pretty close toa “feature-complete” 1.0, and I hope we’ll get there in the months to come.Keep hacking!