Fork me on GitHub
#clojurescript
<
2022-08-24
>
sirwobin11:08:04

Is there a cljs equivalent to Throwable->map?

quoll14:08:45

It might be a bit tricky in JS given that any kind of object can be thrown. I’m guessing that you’re looking to convert an Error object into a map?

quoll16:08:24

It doesn’t attempt to parse the stack trace into a seq, but here is a simple attempt https://gist.github.com/quoll/acb206d2387d5c4f0ae690781eace6d6

quoll16:08:02

It should provide something regardless of the type you give it, but it will provide the most data if you give it something that extends Error

quoll16:08:52

cljs.user=> (Throwable->map {})
{:type cljs.core/PersistentArrayMap, :message "{}"}

cljs.user=> (Throwable->map "Error")
{:type String, :message "Error"}

cljs.user=> (Throwable->map (js/Error "There was an error"))
{:type Error,
 :message "There was an error",
 :stack "Error: There was an error\n    at repl:1:127\n    at repl:9:3\n    at repl:14:4\n    at Script.runInThisContext (node:vm:129:12)\n    at Object.runInThisContext (node:vm:313:38)\n    at Domain.<anonymous> ([stdin]:76:38)\n    at Domain.run (node:domain:389:15)\n    at Socket.<anonymous> ([stdin]:73:29)\n    at Socket.emit (node:events:513:28)\n    at Socket.emit (node:domain:489:12)"}

quoll16:08:45

In case this is useful, I put it on github: https://github.com/quoll/cljs-error

sirwobin08:08:01

That's great, thank you! I was expecting a yes/no 🙂

sirwobin10:08:38

I'd love to see it on clojars too

quoll14:08:43

I will. I just need some tests

jpmonettas13:08:24

hi everybody! I'm trying to figure out if it is possible to implement tooling that can interact with js runtimes (browser, node) thru a clojurescript repl. This is, instead of making tooling that connects via websocket to the js runtime, make everything thru clojurescript repls. Sending a command is just writing a form on the repl, but is there a way of implementing runtime sent events without constantly polling? Something like long polling, where I write on the repl (wait-for-events) and it will block there until something happens en the js runtime and then return?

Ted Ciafardini18:08:13

hello. I’ve been exploring the Google Closure Library a bit & I was wondering if there were any goog.closure classes/methods/vars that people in the community especially appreciate and/or would recommend looking into? gratitude

valtteri18:08:22

There are many “hidden” gems. 🙂 With a quick grep I’ve used functions from these modules: • goog.object • goog.string.format • goog.string.path • goog.date.duration • goog.color • goog.color.alpha • goog.functions • goog.array • goog.crypt.base64 • goog.labs.userAgent.browser

gratitude-danke 2
1
isak19:08:53

Also goog.async.Debouncer, goog.dom.ViewportSizeMonitor

quoll22:08:58

goog.Uri (used by cljs.core) goog.StringBuffer (really useful for portable Java/JavaScript interop, since a number of libraries write to files or string with .append)

quoll22:08:49

I did play a bit with goog.math.Long, but found better ways 🙂

quoll22:08:55

IWriter in cljs.core uses StringBuffer, and it’s all through that namespace

thanks2 1