Skip to content

Commit

Permalink
fix pst for bREPLs
Browse files Browse the repository at this point in the history
bREPL needs to implement IGetError so that it can eval to get :ua-product

just drop any stackframe that starts with "Error"
  • Loading branch information
dnolen committed Mar 9, 2015
1 parent b5c56b9 commit cb9cab1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/clj/cljs/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ str-or-pattern."
(evaluate-form repl-env env "<cljs repl>"
`(when ~e
(pr-str
{:value (.-message ~e)
{:value (str ~e)
:stacktrace (.-stack ~e)})))))]
(display-error repl-env
(if (satisfies? IParseError repl-env)
Expand Down
56 changes: 35 additions & 21 deletions src/clj/cljs/repl/browser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(:refer-clojure :exclude [loaded-libs])
(:require [clojure.java.io :as io]
[clojure.string :as string]
[clojure.edn :as edn]
[cljs.compiler :as comp]
[cljs.util :as util]
[cljs.env :as env]
Expand Down Expand Up @@ -265,38 +266,40 @@
[repl-env st err opts]
(->> st
string/split-lines
(drop 1) ;; drop the error message
(drop-while #(.startsWith % "Error"))
(take-while #(not (.startsWith % " at eval")))
(map #(chrome-st-el->frame % opts))
(remove nil?)
vec))

(comment
(parse-stacktrace nil
"\tat Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4258:8)
\tat Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4288:19)
\tat cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5356:34)
\tat http://localhost:9000/out/cljs/core.js:16971:89
\tat cljs.core.map.cljs$core$map__2 (http://localhost:9000/out/cljs/core.js:16972:3)
\tat http://localhost:9000/out/cljs/core.js:10981:129
\tat cljs.core.LazySeq.sval (http://localhost:9000/out/cljs/core.js:10982:3)
\tat cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (http://localhost:9000/out/cljs/core.js:11073:10)
\tat Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4239:13)
\tat Object.cljs$core$pr_sequential_writer [as pr_sequential_writer] (http://localhost:9000/out/cljs/core.js:28706:14)"
"Error: 1 is not ISeqable
at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4258:8)
at Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4288:19)
at cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5356:34)
at http://localhost:9000/out/cljs/core.js:16971:89
at cljs.core.map.cljs$core$map__2 (http://localhost:9000/out/cljs/core.js:16972:3)
at http://localhost:9000/out/cljs/core.js:10981:129
at cljs.core.LazySeq.sval (http://localhost:9000/out/cljs/core.js:10982:3)
at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (http://localhost:9000/out/cljs/core.js:11073:10)
at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4239:13)
at Object.cljs$core$pr_sequential_writer [as pr_sequential_writer] (http://localhost:9000/out/cljs/core.js:28706:14)"
{:ua-product :chrome}
nil)

(parse-stacktrace nil
"at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4259:8)
\tat Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4289:19)
\tat cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5357:18)
\tat eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:1:106)
\tat eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:9:3)
\tat eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:14:4)
\tat http://localhost:9000/out/clojure/browser/repl.js:23:267
\tat clojure$browser$repl$evaluate_javascript (http://localhost:9000/out/clojure/browser/repl.js:26:4)
\tat Object.callback (http://localhost:9000/out/clojure/browser/repl.js:121:169)
\tat goog.messaging.AbstractChannel.deliver (http://localhost:9000/out/goog/messaging/abstractchannel.js:142:13)"
"Error: 1 is not ISeqable
at Object.cljs$core$seq [as seq] (http://localhost:9000/out/cljs/core.js:4259:8)
at Object.cljs$core$first [as first] (http://localhost:9000/out/cljs/core.js:4289:19)
at cljs$core$ffirst (http://localhost:9000/out/cljs/core.js:5357:18)
at eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:1:106)
at eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:9:3)
at eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:23:272), <anonymous>:14:4)
at http://localhost:9000/out/clojure/browser/repl.js:23:267
at clojure$browser$repl$evaluate_javascript (http://localhost:9000/out/clojure/browser/repl.js:26:4)
at Object.callback (http://localhost:9000/out/clojure/browser/repl.js:121:169)
at goog.messaging.AbstractChannel.deliver (http://localhost:9000/out/goog/messaging/abstractchannel.js:142:13)"
{:ua-product :chrome}
nil)
)
Expand Down Expand Up @@ -330,6 +333,7 @@
[repl-env st err opts]
(->> st
string/split-lines
(drop-while #(.startsWith % "Error"))
(take-while #(not (.startsWith % "eval code")))
(remove string/blank?)
(map #(safari-st-el->frame % opts))
Expand Down Expand Up @@ -424,6 +428,7 @@ http://localhost:9000/out/goog/events/events.js:276:42"
[repl-env st err opts]
(->> st
string/split-lines
(drop-while #(.startsWith % "Error"))
(take-while #(= (.indexOf % "> eval") -1))
(remove string/blank?)
(map #(firefox-st-el->frame % opts))
Expand Down Expand Up @@ -475,6 +480,15 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
repl/IParseStacktrace
(-parse-stacktrace [this st err opts]
(parse-stacktrace this st err opts))
repl/IGetError
(-get-error [this e env opts]
(edn/read-string
(repl/evaluate-form this env "<cljs repl>"
`(when ~e
(pr-str
{:ua-product (clojure.browser.repl/get-ua-product)
:value (str ~e)
:stacktrace (.-stack ~e)})))))
(-evaluate [_ _ _ js] (browser-eval js))
(-load [this provides url]
(load-javascript this provides url))
Expand Down
64 changes: 33 additions & 31 deletions src/cljs/clojure/browser/repl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
(if-let [conn @xpc-connection]
(net/transmit conn :print (pr-str data))))

;; TODO: latest GCL interface for this is different
;; see goog.userAgent.product
(defn get-ua-product []
(cond
(gbrowser/isSafari) :safari
(gbrowser/isChrome) :chrome
(gbrowser/isFirefox) :firefox
(gbrowser/isIE) :ie))

(defn evaluate-javascript
"Process a single block of JavaScript received from the server"
[conn block]
Expand All @@ -40,14 +49,7 @@
:value (str (js* "eval(~{block})"))}
(catch :default e
{:status :exception
;; TODO: latest GCL interface for this is different
;; see goog.userAgent.product
:ua-product
(cond
(gbrowser/isSafari) :safari
(gbrowser/isChrome) :chrome
(gbrowser/isFirefox) :firefox
(gbrowser/isIE) :ie)
:ua-product (get-ua-product)
:value (str e)
:stacktrace
(if (.hasOwnProperty e "stack")
Expand All @@ -62,15 +64,15 @@
"Send data to be printed in the REPL. If there is an error, try again
up to 10 times."
([url data]
(send-print url data 0))
(send-print url data 0))
([url data n]
(let [conn (net/xhr-connection)]
(event/listen conn :error
(fn [_]
(if (< n 10)
(send-print url data (inc n))
(.log js/console (str "Could not send " data " after " n " attempts.")))))
(net/transmit conn url "POST" data nil 0))))
(let [conn (net/xhr-connection)]
(event/listen conn :error
(fn [_]
(if (< n 10)
(send-print url data (inc n))
(.log js/console (str "Could not send " data " after " n " attempts.")))))
(net/transmit conn url "POST" data nil 0))))

(def order (atom 0))

Expand All @@ -83,26 +85,26 @@
(if-let [repl-connection (net/xpc-connection)]
(let [connection (net/xhr-connection)]
(event/listen connection
:success
(fn [e]
(net/transmit
repl-connection
:evaluate-javascript
(.getResponseText (.-currentTarget e)
()))))
:success
(fn [e]
(net/transmit
repl-connection
:evaluate-javascript
(.getResponseText (.-currentTarget e)
()))))

(net/register-service repl-connection
:send-result
(fn [data]
(send-result connection url (wrap-message :result data))))
:send-result
(fn [data]
(send-result connection url (wrap-message :result data))))

(net/register-service repl-connection
:print
(fn [data]
(send-print url (wrap-message :print data))))
:print
(fn [data]
(send-print url (wrap-message :print data))))

(net/connect repl-connection
(constantly nil))
(constantly nil))

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

0 comments on commit cb9cab1

Please sign in to comment.