Closed FieryCod closed 6 years ago
/Users/karol/workspace/clojure/lein-figwheel/sidecar/src/figwheel_sidecar/components/figwheel_server.clj
read-msg
method receives something like {:value {#js {:prop1 blabla}}
when using cider-eval-last-sexp
.
Therefore parsing that string returns an error. What I think is that I should just regexp the string and remove #js
. What do you think @bhauman?
EDIT: This is what read-msg method really receives
"{:figwheel-event "callback", :callback-name "figwheel_callback_37403", :content {:status :success, :out "", :ua-product :chrome, :value #js {:_toBuf #object[toBuf], :createCipher #object[createCipher], :createCipheriv #object[createCipheriv], :createDecipher #object[createDecipher], :createDecipheriv #object[createDecipheriv], :createDiffieHellman #object[createDiffieHellman], :createDiffieHellmanGroup #object[createDiffieHellmanGroup], :createECDH #object[createECDH], :createHash #object[createHash], :createHmac #object[createHmac], :createSign #object[createSign], :createVerify #object[createVerify], :getCiphers #object[Function], :getCurves #object[Function], :getDiffieHellman #object[createDiffieHellmanGroup], :getHashes #object[Function], :pbkdf2 #object[pbkdf2], :pbkdf2Sync #object[pbkdf2Sync], :privateDecrypt #object[Function], :privateEncrypt #object[Function], :prng #object[randomBytes], :pseudoRandomBytes #object[randomBytes], :publicDecrypt #object[Function], :publicEncrypt #object[Function], :randomBytes #object[randomBytes], :randomFill #object[randomFill], :randomFillSync #object[randomFillSync], :rng #object[randomBytes], :setEngine #object[setEngine], :timingSafeEqual #object[timingSafeEqual], :Certificate #object[Certificate], :Cipher #object[Cipher], :Cipheriv #object[Cipheriv], :Decipher #object[Decipher], :Decipheriv #object[Decipheriv], :DiffieHellman #object[DiffieHellman], :DiffieHellmanGroup #object[DiffieHellmanGroup], :ECDH #object[ECDH], :Hash #object[Hash], :Hmac #object[Hmac], :Sign #object[Sign], :Verify #object[Verify], :DEFAULT_ENCODING "buffer", :constants #object[Object], :createCredentials #object[createSecureContext], :Credentials #object[SecureContext]}}}"
Splitting on the #js
is unfortunately not a solution to consider here. Reading errors need to be fixed by changing the reader so that it reads better.
And I'm not sure this is a reading error neccessarily because figwheel.main has the exact same code for reading responses from the client.
read-msg
is not a reader stuff?
(defn- replace-unparsable-js
"Replaces #js in msg with 'nil to avoid read error when importing built-in Node.js libraries (CLJS 1.10)"
[msg]
(string/replace msg #"(#js \{[:#\w\[\]\", ]*\})" "nil"))
(defn read-msg [data]
(try
(println (replace-unparsable-js data))
(let [msg (edn/read-string (replace-unparsable-js data))]
(if (and (map? msg) (:figwheel-event msg))
msg
{}))
(catch Exception e
(println "Figwheel: message from client couldn't be read!")
{})))
This is what solves the problem. If it doesn't satisfy you please point me where in code should I look for the problem.
Step to reproduce:
cider-eval-last-sexp
on ns formError: Figwheel: message from client couldn't be read! Eval timed out! No stacktrace available.
Stacktrace:
When trying to evaluate the whole buffer then the evaluation succeeds.
Everything works as it should using the figwheel-main.