Skip to content

Improve ClojureScript error and compiler-warning rendering #4043

Description

@bbatsov

When a ClojureScript evaluation fails or the compiler emits a warning, the experience is noticeably poorer than for Clojure: you get a plain message overlay and the raw error text, with no clickable jump to the offending source location and no cause/frame view.

Why it's degraded today

Clojure errors flow through analyze-last-stacktrace, which analyzes a JVM Throwable and returns rich structured causes/frames that cider-stacktrace renders. ClojureScript errors are JavaScript errors with no JVM exception structure, so:

  • cljs connections lack the jvm-compilation-errors capability, and cider--display-error-unobtrusively is used instead - it just concatenates the cause messages into an overlay (cider-compilation.el ~336-345);
  • compiler warnings (Use of undeclared Var ... at line N column M) arrive as plain stderr text and aren't parsed, so there's no jump-to-location.

Suggested approach (two phases)

Phase 1 - client side (higher ROI). Parse cljs compiler-warning/error text to extract file/line/column and turn it into a clickable source location + a better overlay, reusing the existing cider-extract-error-info / cider--find-last-error-location machinery (which currently only matches the JVM at ns (file.clj:line:col) shape). The wrinkle is that warning/error text varies by backend (piggieback vs shadow-cljs vs figwheel), so the parser has to be validated against real output rather than guessed.

Phase 2 - middleware, optional/harder. Teach cider-nrepl's stacktrace path to detect a cljs REPL and return structured location/cause data extracted from the piggieback/shadow JS error object, so cljs can get a richer view closer to Clojure's. There's already a test/cljs/cider/nrepl/middleware/cljs_stacktrace_test.clj to build on.

Validating against live REPLs

This is the key reason it wasn't done blind: cider-nrepl has the infra to capture real formats - node + cider/piggieback, a test/shadow-cljs harness, and the existing cljs stacktrace test. Phase 1's parser should be pinned against actual node/piggieback and shadow-cljs warning output before shipping.

Comes out of the ClojureScript support review; see the cljs overview's Feature support section. Needs a companion change in cider-nrepl for Phase 2.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions