[#589] Fix REPL error locations
This commit is contained in:
parent
72ec14349c
commit
6d2b026dd2
3 changed files with 37 additions and 19 deletions
|
|
@ -17,14 +17,25 @@
|
|||
"Default :caught hook for repl"
|
||||
[^Throwable e]
|
||||
(sci/with-bindings {sci/out @sci/err}
|
||||
(let [d (ex-data e)
|
||||
(let [{:keys [:file :line :column] :as d} (ex-data e)
|
||||
sci-error? (identical? :sci/error (:type d))
|
||||
ex-name (when sci-error?
|
||||
(some-> ^Throwable (ex-cause e)
|
||||
.getClass .getName))]
|
||||
.getClass .getName))
|
||||
ex-message (when-let [m (.getMessage e)]
|
||||
(when-not (str/blank? m)
|
||||
m))]
|
||||
(sio/println (str ex-name
|
||||
(when-let [m (.getMessage e)]
|
||||
(str ": " m)) ))
|
||||
(when ex-message
|
||||
(str (when ex-name ": ")
|
||||
ex-message))
|
||||
(when file
|
||||
(str
|
||||
(when (or ex-name ex-message)
|
||||
" ")
|
||||
"[at " file
|
||||
(when line
|
||||
(str ":" line ":" column))"]"))))
|
||||
(sio/flush))))
|
||||
|
||||
(defn repl
|
||||
|
|
@ -51,18 +62,19 @@
|
|||
v))))
|
||||
:eval (or eval
|
||||
(fn [expr]
|
||||
(let [ret (eval-form (update sci-ctx
|
||||
:env
|
||||
(fn [env]
|
||||
(swap! env update-in [:namespaces 'clojure.core]
|
||||
assoc
|
||||
'*1 *1
|
||||
'*2 *2
|
||||
'*3 *3
|
||||
'*e *e)
|
||||
env))
|
||||
expr)]
|
||||
ret)))
|
||||
(sci/with-bindings {sci/file "<repl>"}
|
||||
(let [ret (eval-form (update sci-ctx
|
||||
:env
|
||||
(fn [env]
|
||||
(swap! env update-in [:namespaces 'clojure.core]
|
||||
assoc
|
||||
'*1 *1
|
||||
'*2 *2
|
||||
'*3 *3
|
||||
'*e *e)
|
||||
env))
|
||||
expr)]
|
||||
ret))))
|
||||
:need-prompt (or need-prompt (fn [] true))
|
||||
:prompt (or prompt #(sio/printf "%s=> " (vars/current-ns-name)))
|
||||
:flush (or flush sio/flush)
|
||||
|
|
|
|||
|
|
@ -541,7 +541,11 @@
|
|||
(deftest repl-test
|
||||
(is (str/includes? (test-utils/bb "(ns foo) ::foo" "--repl") ":foo/foo"))
|
||||
(is (str/includes? (test-utils/bb "[*warn-on-reflection* (set! *warn-on-reflection* true) *warn-on-reflection*]")
|
||||
"[false true true]")))
|
||||
"[false true true]"))
|
||||
(let [sw (java.io.StringWriter.)]
|
||||
(sci/with-bindings {sci/err sw}
|
||||
(test-utils/bb {:in "x" :err sw} "--repl"))
|
||||
(is (str/includes? (str sw) "Could not resolve symbol: x [at <repl>:1:1]"))))
|
||||
|
||||
;;;; Scratch
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@
|
|||
(let [os (java.io.StringWriter.)
|
||||
es (if-let [err (:err input-or-opts)]
|
||||
err (java.io.StringWriter.))
|
||||
is (when (string? input-or-opts)
|
||||
(java.io.StringReader. input-or-opts))
|
||||
in (if (string? input-or-opts)
|
||||
input-or-opts (:in input-or-opts))
|
||||
is (when in
|
||||
(java.io.StringReader. in))
|
||||
bindings-map (cond-> {sci/out os
|
||||
sci/err es}
|
||||
is (assoc sci/in is))]
|
||||
|
|
|
|||
Loading…
Reference in a new issue