Trace by default in REPL-driven development
A repl or nREPL session now turns tail-frame tracing on, so an uncaught error in evaluated/reloaded code shows a tail-frame backtrace with no JOLT_TRACE set. The REPL and nREPL catch errors themselves rather than going through the uncaught reporter, so they now print the history backtrace via a new jolt.host/backtrace- string (history-only — the live continuation in a REPL is just REPL machinery). Because the recording is baked in at compile time, only code compiled while a session is live is traced; reload a namespace to trace already-loaded code. JOLT_TRACE=1 still forces it on for a whole run (a plain -M:run traces its own load); JOLT_TRACE=0 forces it off even in a session. No seed change — jolt.main/jolt.nrepl are runtime-loaded and compile-eval.ss / source-registry.ss are host files.
This commit is contained in:
parent
a3e2365217
commit
7167af4830
6 changed files with 89 additions and 23 deletions
|
|
@ -147,6 +147,9 @@
|
|||
;; loaded — same context a run gets, so (require '[some.lib]) works in the REPL.
|
||||
(try (apply-project! (deps/resolve-project (project-dir)))
|
||||
(catch :default _ nil))
|
||||
;; REPL-driven development: trace by default so an uncaught error in evaluated
|
||||
;; code shows a tail-frame backtrace, no JOLT_TRACE needed (JOLT_TRACE=0 opts out).
|
||||
(jolt.host/enable-trace!)
|
||||
(println (str ";; jolt " (version) " repl — :repl/quit or ^D to exit"))
|
||||
(loop []
|
||||
(let [form (repl-read-form)]
|
||||
|
|
@ -160,7 +163,9 @@
|
|||
(catch :default e
|
||||
(println "error:" (or (ex-message e)
|
||||
(try ((resolve 'jolt.host/condition-message) e) (catch :default _ nil))
|
||||
(pr-str e)))))
|
||||
(pr-str e)))
|
||||
(when-let [bt (jolt.host/backtrace-string)]
|
||||
(print bt))))
|
||||
(recur)))))))
|
||||
|
||||
;; A deps.edn :tasks entry: a string is a shell command; a map is {:main-opts …}.
|
||||
|
|
|
|||
|
|
@ -188,7 +188,10 @@
|
|||
(try (when (and ns-str (not (str/blank? ns-str)) (find-ns (symbol ns-str)))
|
||||
(in-ns (symbol ns-str)))
|
||||
(reset! result (load-string code))
|
||||
(catch :default e (reset! err (err-msg e)))))]
|
||||
(catch :default e
|
||||
(reset! err (str (err-msg e)
|
||||
(when-let [bt (jolt.host/backtrace-string)]
|
||||
(str "\n" bt)))))))]
|
||||
{:value (when (nil? @err) (pr-str @result))
|
||||
:out out
|
||||
:ns (str (ns-name *ns*))
|
||||
|
|
@ -277,6 +280,11 @@
|
|||
no-op."
|
||||
([port] (start port nil))
|
||||
([port middleware]
|
||||
;; An nREPL session is REPL-driven development: trace by default so an uncaught
|
||||
;; error in code evaluated over the connection shows a tail-frame backtrace, with
|
||||
;; no JOLT_TRACE needed. Covers both `--nrepl-server` and an app that starts its
|
||||
;; own server under `-M:run` (reload a namespace to trace already-loaded code).
|
||||
(jolt.host/enable-trace!)
|
||||
(let [handler (build-handler (resolve-middleware (or middleware [])))
|
||||
fd (listen-socket port) ; throws on bind/listen failure
|
||||
stopped (atom false)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue