Closed mfikes closed 7 years ago
I did a little digging into this and can see why it is occurring. Summary: Figwheel sends messages from the JavaScript environment back to Clojure serializing arguments to "RPC" calls as edn, and for the REPL print fns, the conversion to strings occurs on the Clojure side.
Perhaps another alternative would be to do the string conversions—only for the REPL print message—on the JavaScript side instead so that the arguments on the receiving end are (edn) strings.
That might open the door to being able to (*print-fn* #js {:foo 1})
, and the exception type mentioned above. If you look at what the Node REPL does, it just uses console logging of the raw JavaScript values. (As an aside, I just noticed that Planck wasn't matching the Node REPL's behavior either and got it to be fairly close by making use of JSON/stringify, essentially using something like
(defn ->string
[x]
(js/JSON.stringify x nil " "))
Of course, if Figwheel were to consider something like this for non-string args, it suspect it would be wise to check (and (exists? js/JSON) (some? js/JSON.stringify))
One more bit of follow up on this: It appears that Error objects are given special treatment, and instead of JSON stringified representation, the message and stack properties are extracted to form the string representation.
Alrighty just want to let you know I'm going to take a look at this.
I've fixed this but if we are keen on keeping the contract for print-fn to only take strings let me know.
If you try to apply
*print-fn*
or*print-err-fn*
to an exception, you get "Figwheel: message from client couldn't be read!"Example:
Note: For comparison here is what you get in the Node REPL: