Skip to content

Commit cb9cab1

Browse files
author
dnolen
committed
fix pst for bREPLs
bREPL needs to implement IGetError so that it can eval to get :ua-product just drop any stackframe that starts with "Error"
1 parent b5c56b9 commit cb9cab1

File tree

3 files changed

+69
-53
lines changed

3 files changed

+69
-53
lines changed

src/clj/cljs/repl.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ str-or-pattern."
10141014
(evaluate-form repl-env env "<cljs repl>"
10151015
`(when ~e
10161016
(pr-str
1017-
{:value (.-message ~e)
1017+
{:value (str ~e)
10181018
:stacktrace (.-stack ~e)})))))]
10191019
(display-error repl-env
10201020
(if (satisfies? IParseError repl-env)

src/clj/cljs/repl/browser.clj

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
(:refer-clojure :exclude [loaded-libs])
1111
(:require [clojure.java.io :as io]
1212
[clojure.string :as string]
13+
[clojure.edn :as edn]
1314
[cljs.compiler :as comp]
1415
[cljs.util :as util]
1516
[cljs.env :as env]
@@ -265,38 +266,40 @@
265266
[repl-env st err opts]
266267
(->> st
267268
string/split-lines
268-
(drop 1) ;; drop the error message
269+
(drop-while #(.startsWith % "Error"))
269270
(take-while #(not (.startsWith % " at eval")))
270271
(map #(chrome-st-el->frame % opts))
271272
(remove nil?)
272273
vec))
273274

274275
(comment
275276
(parse-stacktrace nil
276-
"\tat Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4258:8)
277-
\tat Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4288:19)
278-
\tat cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5356:34)
279-
\tat http://localhost:9000/out/cljs/core.js:16971:89
280-
\tat cljs.core.map.cljs$core$map__2 (http://localhost:9000/out/cljs/core.js:16972:3)
281-
\tat http://localhost:9000/out/cljs/core.js:10981:129
282-
\tat cljs.core.LazySeq.sval (http://localhost:9000/out/cljs/core.js:10982:3)
283-
\tat cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (http://localhost:9000/out/cljs/core.js:11073:10)
284-
\tat Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4239:13)
285-
\tat Object.cljs$core$pr_sequential_writer [as pr_sequential_writer] (http://localhost:9000/out/cljs/core.js:28706:14)"
277+
"Error: 1 is not ISeqable
278+
at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4258:8)
279+
at Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4288:19)
280+
at cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5356:34)
281+
at http://localhost:9000/out/cljs/core.js:16971:89
282+
at cljs.core.map.cljs$core$map__2 (http://localhost:9000/out/cljs/core.js:16972:3)
283+
at http://localhost:9000/out/cljs/core.js:10981:129
284+
at cljs.core.LazySeq.sval (http://localhost:9000/out/cljs/core.js:10982:3)
285+
at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (http://localhost:9000/out/cljs/core.js:11073:10)
286+
at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4239:13)
287+
at Object.cljs$core$pr_sequential_writer [as pr_sequential_writer] (http://localhost:9000/out/cljs/core.js:28706:14)"
286288
{:ua-product :chrome}
287289
nil)
288290

289291
(parse-stacktrace nil
290-
"at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4259:8)
291-
\tat Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4289:19)
292-
\tat cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5357:18)
293-
\tat eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:1:106)
294-
\tat eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:9:3)
295-
\tat eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:14:4)
296-
\tat http://localhost:9000/out/clojure/browser/repl.js:23:267
297-
\tat clojure$browser$repl$evaluate_javascript (http://localhost:9000/out/clojure/browser/repl.js:26:4)
298-
\tat Object.callback (http://localhost:9000/out/clojure/browser/repl.js:121:169)
299-
\tat goog.messaging.AbstractChannel.deliver (http://localhost:9000/out/goog/messaging/abstractchannel.js:142:13)"
292+
"Error: 1 is not ISeqable
293+
at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4259:8)
294+
at Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4289:19)
295+
at cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5357:18)
296+
at eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:1:106)
297+
at eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:9:3)
298+
at eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:14:4)
299+
at http://localhost:9000/out/clojure/browser/repl.js:23:267
300+
at clojure$browser$repl$evaluate_javascript (http://localhost:9000/out/clojure/browser/repl.js:26:4)
301+
at Object.callback (http://localhost:9000/out/clojure/browser/repl.js:121:169)
302+
at goog.messaging.AbstractChannel.deliver (http://localhost:9000/out/goog/messaging/abstractchannel.js:142:13)"
300303
{:ua-product :chrome}
301304
nil)
302305
)
@@ -330,6 +333,7 @@
330333
[repl-env st err opts]
331334
(->> st
332335
string/split-lines
336+
(drop-while #(.startsWith % "Error"))
333337
(take-while #(not (.startsWith % "eval code")))
334338
(remove string/blank?)
335339
(map #(safari-st-el->frame % opts))
@@ -424,6 +428,7 @@ http://localhost:9000/out/goog/events/events.js:276:42"
424428
[repl-env st err opts]
425429
(->> st
426430
string/split-lines
431+
(drop-while #(.startsWith % "Error"))
427432
(take-while #(= (.indexOf % "> eval") -1))
428433
(remove string/blank?)
429434
(map #(firefox-st-el->frame % opts))
@@ -475,6 +480,15 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
475480
repl/IParseStacktrace
476481
(-parse-stacktrace [this st err opts]
477482
(parse-stacktrace this st err opts))
483+
repl/IGetError
484+
(-get-error [this e env opts]
485+
(edn/read-string
486+
(repl/evaluate-form this env "<cljs repl>"
487+
`(when ~e
488+
(pr-str
489+
{:ua-product (clojure.browser.repl/get-ua-product)
490+
:value (str ~e)
491+
:stacktrace (.-stack ~e)})))))
478492
(-evaluate [_ _ _ js] (browser-eval js))
479493
(-load [this provides url]
480494
(load-javascript this provides url))

src/cljs/clojure/browser/repl.cljs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
(if-let [conn @xpc-connection]
3232
(net/transmit conn :print (pr-str data))))
3333

34+
;; TODO: latest GCL interface for this is different
35+
;; see goog.userAgent.product
36+
(defn get-ua-product []
37+
(cond
38+
(gbrowser/isSafari) :safari
39+
(gbrowser/isChrome) :chrome
40+
(gbrowser/isFirefox) :firefox
41+
(gbrowser/isIE) :ie))
42+
3443
(defn evaluate-javascript
3544
"Process a single block of JavaScript received from the server"
3645
[conn block]
@@ -40,14 +49,7 @@
4049
:value (str (js* "eval(~{block})"))}
4150
(catch :default e
4251
{:status :exception
43-
;; TODO: latest GCL interface for this is different
44-
;; see goog.userAgent.product
45-
:ua-product
46-
(cond
47-
(gbrowser/isSafari) :safari
48-
(gbrowser/isChrome) :chrome
49-
(gbrowser/isFirefox) :firefox
50-
(gbrowser/isIE) :ie)
52+
:ua-product (get-ua-product)
5153
:value (str e)
5254
:stacktrace
5355
(if (.hasOwnProperty e "stack")
@@ -62,15 +64,15 @@
6264
"Send data to be printed in the REPL. If there is an error, try again
6365
up to 10 times."
6466
([url data]
65-
(send-print url data 0))
67+
(send-print url data 0))
6668
([url data n]
67-
(let [conn (net/xhr-connection)]
68-
(event/listen conn :error
69-
(fn [_]
70-
(if (< n 10)
71-
(send-print url data (inc n))
72-
(.log js/console (str "Could not send " data " after " n " attempts.")))))
73-
(net/transmit conn url "POST" data nil 0))))
69+
(let [conn (net/xhr-connection)]
70+
(event/listen conn :error
71+
(fn [_]
72+
(if (< n 10)
73+
(send-print url data (inc n))
74+
(.log js/console (str "Could not send " data " after " n " attempts.")))))
75+
(net/transmit conn url "POST" data nil 0))))
7476

7577
(def order (atom 0))
7678

@@ -83,26 +85,26 @@
8385
(if-let [repl-connection (net/xpc-connection)]
8486
(let [connection (net/xhr-connection)]
8587
(event/listen connection
86-
:success
87-
(fn [e]
88-
(net/transmit
89-
repl-connection
90-
:evaluate-javascript
91-
(.getResponseText (.-currentTarget e)
92-
()))))
88+
:success
89+
(fn [e]
90+
(net/transmit
91+
repl-connection
92+
:evaluate-javascript
93+
(.getResponseText (.-currentTarget e)
94+
()))))
9395

9496
(net/register-service repl-connection
95-
:send-result
96-
(fn [data]
97-
(send-result connection url (wrap-message :result data))))
97+
:send-result
98+
(fn [data]
99+
(send-result connection url (wrap-message :result data))))
98100

99101
(net/register-service repl-connection
100-
:print
101-
(fn [data]
102-
(send-print url (wrap-message :print data))))
103-
102+
:print
103+
(fn [data]
104+
(send-print url (wrap-message :print data))))
105+
104106
(net/connect repl-connection
105-
(constantly nil))
107+
(constantly nil))
106108

107109
(js/setTimeout #(send-result connection url (wrap-message :ready "ready")) 50))
108110
(js/alert "No 'xpc' param provided to child iframe.")))

0 commit comments

Comments
 (0)