cljs-bean icon indicating copy to clipboard operation
cljs-bean copied to clipboard

How to use bean and ->clj on objects like js/Error?

Open introom opened this issue 2 years ago • 3 comments

For now, for the following code:

(def e (js/Error. "test string"))
;; 1
(bean/e) 
;; 2
(->clj/e)
  1. gives
{:clojure$core$protocols$Datafiable$ #js {}, :clojure$core$protocols$Datafiable$datafy$arity$1 #object[Function]
  1. gives
#object[Error Error: test string]

Would be better if it can give things like

{"message":foo,  "line":foo,  "column":foo,  "stack":foo}

introom avatar Apr 16 '22 15:04 introom

Relevant: https://clojure.atlassian.net/browse/CLJS-3014

mfikes avatar Apr 16 '22 15:04 mfikes

Not sure on the details. Isn't it possible to use all the possible keys from an object to form a bean? So it will work not only in the specific case of Error->map ?

introom avatar Apr 16 '22 15:04 introom

@introom One issue here is that js-keys returns an empty array when applied to a js/Error object.

mfikes avatar Apr 17 '22 04:04 mfikes