[#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"
|
"Default :caught hook for repl"
|
||||||
[^Throwable e]
|
[^Throwable e]
|
||||||
(sci/with-bindings {sci/out @sci/err}
|
(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))
|
sci-error? (identical? :sci/error (:type d))
|
||||||
ex-name (when sci-error?
|
ex-name (when sci-error?
|
||||||
(some-> ^Throwable (ex-cause e)
|
(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
|
(sio/println (str ex-name
|
||||||
(when-let [m (.getMessage e)]
|
(when ex-message
|
||||||
(str ": " m)) ))
|
(str (when ex-name ": ")
|
||||||
|
ex-message))
|
||||||
|
(when file
|
||||||
|
(str
|
||||||
|
(when (or ex-name ex-message)
|
||||||
|
" ")
|
||||||
|
"[at " file
|
||||||
|
(when line
|
||||||
|
(str ":" line ":" column))"]"))))
|
||||||
(sio/flush))))
|
(sio/flush))))
|
||||||
|
|
||||||
(defn repl
|
(defn repl
|
||||||
|
|
@ -51,18 +62,19 @@
|
||||||
v))))
|
v))))
|
||||||
:eval (or eval
|
:eval (or eval
|
||||||
(fn [expr]
|
(fn [expr]
|
||||||
(let [ret (eval-form (update sci-ctx
|
(sci/with-bindings {sci/file "<repl>"}
|
||||||
:env
|
(let [ret (eval-form (update sci-ctx
|
||||||
(fn [env]
|
:env
|
||||||
(swap! env update-in [:namespaces 'clojure.core]
|
(fn [env]
|
||||||
assoc
|
(swap! env update-in [:namespaces 'clojure.core]
|
||||||
'*1 *1
|
assoc
|
||||||
'*2 *2
|
'*1 *1
|
||||||
'*3 *3
|
'*2 *2
|
||||||
'*e *e)
|
'*3 *3
|
||||||
env))
|
'*e *e)
|
||||||
expr)]
|
env))
|
||||||
ret)))
|
expr)]
|
||||||
|
ret))))
|
||||||
:need-prompt (or need-prompt (fn [] true))
|
:need-prompt (or need-prompt (fn [] true))
|
||||||
:prompt (or prompt #(sio/printf "%s=> " (vars/current-ns-name)))
|
:prompt (or prompt #(sio/printf "%s=> " (vars/current-ns-name)))
|
||||||
:flush (or flush sio/flush)
|
:flush (or flush sio/flush)
|
||||||
|
|
|
||||||
|
|
@ -541,7 +541,11 @@
|
||||||
(deftest repl-test
|
(deftest repl-test
|
||||||
(is (str/includes? (test-utils/bb "(ns foo) ::foo" "--repl") ":foo/foo"))
|
(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*]")
|
(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
|
;;;; Scratch
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,10 @@
|
||||||
(let [os (java.io.StringWriter.)
|
(let [os (java.io.StringWriter.)
|
||||||
es (if-let [err (:err input-or-opts)]
|
es (if-let [err (:err input-or-opts)]
|
||||||
err (java.io.StringWriter.))
|
err (java.io.StringWriter.))
|
||||||
is (when (string? input-or-opts)
|
in (if (string? input-or-opts)
|
||||||
(java.io.StringReader. input-or-opts))
|
input-or-opts (:in input-or-opts))
|
||||||
|
is (when in
|
||||||
|
(java.io.StringReader. in))
|
||||||
bindings-map (cond-> {sci/out os
|
bindings-map (cond-> {sci/out os
|
||||||
sci/err es}
|
sci/err es}
|
||||||
is (assoc sci/in is))]
|
is (assoc sci/in is))]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue