Skip to content

Commit 8f49d93

Browse files
mfikesswannodette
authored andcommitted
CLJS-3011: Port improved runtime exception printing to non-Node REPLs
1 parent 91be632 commit 8f49d93

File tree

4 files changed

+7
-32
lines changed

4 files changed

+7
-32
lines changed

src/main/cljs/clojure/browser/repl.cljs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@
6969
:value (str (js* "eval(~{block})"))}
7070
(catch :default e
7171
{:status :exception
72-
:ua-product (get-ua-product)
73-
:value (str e)
74-
:stacktrace
75-
(if (.hasOwnProperty e "stack")
76-
(.-stack e)
77-
"No stacktrace available.")}))]
72+
:value (cljs.repl/error->str e)}))]
7873
(pr-str result)))
7974

8075
(defn send-result [connection url data]

src/main/clojure/cljs/repl/graaljs.clj

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,25 +148,12 @@
148148
{:status :success
149149
:value (if-let [r (eval-str engine js)] (safe-to-string r) "")}
150150
(catch ScriptException e
151-
(let [^Throwable root-cause (clojure.stacktrace/root-cause e)]
152-
{:status :exception
153-
:value (.getMessage root-cause)
154-
:stacktrace
155-
(apply str
156-
(interpose "\n"
157-
(map #(subs % 5)
158-
(filter #(clojure.string/starts-with? % "<js>.")
159-
(map str
160-
(.getStackTrace root-cause))))))}))
151+
{:status :exception
152+
:value (eval-str engine "cljs.repl.error__GT_str(cljs.core._STAR_e)")})
161153
(catch Throwable e
162154
(let [^Throwable root-cause (clojure.stacktrace/root-cause e)]
163155
{:status :exception
164-
:value (.getMessage root-cause)
165-
:stacktrace
166-
(apply str
167-
(interpose "\n"
168-
(map str
169-
(.getStackTrace root-cause))))}))))
156+
:value (cljs.repl/ex-str (cljs.repl/ex-triage (Throwable->map root-cause)))}))))
170157
(-load [{engine :engine :as this} ns url]
171158
(load-ns engine ns))
172159
(-tear-down [this]

src/main/clojure/cljs/repl/nashorn.clj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,11 @@
138138
(catch ScriptException e
139139
(let [^Throwable root-cause (clojure.stacktrace/root-cause e)]
140140
{:status :exception
141-
:value (.getMessage root-cause)
142-
:stacktrace (NashornException/getScriptStackString root-cause)}))
141+
:value (eval-str engine "cljs.repl.error__GT_str(cljs.core._STAR_e)")}))
143142
(catch Throwable e
144143
(let [^Throwable root-cause (clojure.stacktrace/root-cause e)]
145144
{:status :exception
146-
:value (.getMessage root-cause)
147-
:stacktrace
148-
(apply str
149-
(interpose "\n"
150-
(map str
151-
(.getStackTrace root-cause))))}))))
145+
:value (cljs.repl/ex-str (cljs.repl/ex-triage (Throwable->map root-cause)))}))))
152146
(-load [{engine :engine :as this} ns url]
153147
(load-ns engine ns))
154148
(-tear-down [this]

src/main/clojure/cljs/repl/rhino.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@
8686
(ScriptableObject/putProperty top-level "_STAR_e"
8787
(Context/javaToJS ex scope))
8888
{:status :exception
89-
:value (.toString ex)
90-
:stacktrace (stacktrace ex)}))))
89+
:value (cljs.repl/ex-str (cljs.repl/ex-triage (Throwable->map ex)))}))))
9190

9291
(defn load-file
9392
"Load a JavaScript. This is needed to load JavaScript files before the Rhino

0 commit comments

Comments
 (0)