Fork me on GitHub

How do I make a writer for JS error object to send thru wire? When I do (pr-str (js/Error. "OOPS")) it gives me "#object[Error Error: OOPS]" . And (js->clj (js/Error. "Oops!")) gives something like #object[Error Error: Oops!] . I want to make a writter for JS errors so I can send then thru wire (maybe EDN) and deserialize in other end...


I replied on SO.

βœ”οΈ 4

@stebokas what would you possibly deserialize it to on the other end? I would strongly suggest keeping exceptions out of your data


Not everything needs deserialization. It may be just for monitoring purposes.


yes this is for logging


but it would still be better to catch the exception client-side and then "log" with more context? (try (some-weird-stuff) (catch :default e (log "hey this weird stuff failed" some more data and context)))


What if it's the (.-onerror js/window)?


I use this and then send to server that puts al;l to SystemD


You can't guarantee nothing bad will happen outside of your try block. And it's better to know about it.


but the problem is that client can not persist logs...


onerror is even easier .. just convert it to something data directly


why force pr-str to do it when you have the the thing right there and can convert it


I think that's exactly what the question was about. :) "How to convert it to something I can send over the wire".


I.e. the intention wasn't to make pr-str work with js/Error. The intention was serialization of any kind.

βœ”οΈ 4

assuming e is the exception then (.-message e) and/or (.-stack e)

πŸ‘ 4

thats pretty much the only thing you get


both are strings


Not that robust though. stack is not a standard thing (although maybe all modern browsers support it - I have no clue) and there are other fields (although they're probably incorporated in the stack, but then you'd have to parse it). Also, nothing prevents some JS library from doing something like = ['this', 'and', 'that']. It may be useful to not lose that information.


Personally, I don't see any argument against just iterating over getOwnPropertyNames and not even thinking about the particular fields.

πŸ‘ 4

but that opens you up to things not being printable again πŸ˜›


Well, js->clj for good measure. :) And if that fails, then I'd just be content with what I have. But I just realized that in JS, we also can easily have circular references. That would be no fun at all.


Hi, I'm trying to set up a clojure script environment with figwheel. Going through figwheel's quick -start ( ), everything is going fine, until changes in my core.cljs should be automatically reflected in my browser, which it doesn't. The repl is working fine (I can send js/alerts or log things to the console), but files aren't automatically reloading. I assume it's the same problem like here: so I added the edn files as suggested, without success. I am using lein figwheel instead of his

clj -m figwheel.main --compile hello.cruel-world --repl
though. Does leiningen use the edn files or do I need to put this info into my project.clj somehow? I'm working in WSL 2 on windows 10, not sure if that's relevant.

Dania Rifki12:02:19

Using Lumo, I'm trying to make a Mastodon bot that reposts posts from r/lispmemes to Mastodon, I found this earlier, unfortunately it uses an old mastodon library that seems to be abandoned. I'm currently looking at this, but it requires async/await. I know you can use something like Andare for this but I'm still not sure how you'd translate this example to cljs


@UTXH1TJM9 javascript's async/`await` are just syntax sugar on top of the built-in Promise objects. You won't need andare or anything else which implements clojure.core.async in order to handle Promises in cljs.


the import statements correspond to require in cljs. For any async methods (methods which return a Promise), you can use then/`catch` chains like you would in pre-await js.


then/catch chains in cljs are a little easier to manage with the -> threading operator. others here might have a better way


A simple example:

$ cat ls.cljs
  #!/usr/bin/env lumo
  (require 'fs)
  (require '[util :refer [promisify]])

  (def read-dir (promisify fs/readdir))

  (-> (read-dir "." #js {:encoding "utf-8"})
      (.then (fn [filenames] (doall (map println filenames))))
      (.catch #(println "Oops! => " %)))
  $ chmod 755 ls.cljs
  $ ./ls.cljs


The other day I was designing a small website and was reminded of how frustrating it is to find a nice font that fits one's design. Chrome devtools seems to lack an interactive font picker, correct? That made me think - given clojurescript's emphasis on a 'live coding' environment (e.g. figwheel, shadow-cljs) it might make sense to have some tooling that aides design. I can think of e.g. a dev-only widget that shows up in the current page, interacts with Google Fonts, offering a font picker, and mutating the current page' CSS out of our choice. Anyone has played with something similar? (This is more curiosity than an actual need)


doesn't the google fonts stuff give you exactly that?


it's not an interactive process, correct? you have to have open in a second tab, then copy/paste. I want to try 100 fonts in 10 seconds, over my own website


That sounds useful.


I bet react hooks had something for this, they are pretty keen on dev tools built on it

πŸ‘€ 4

no i mean you can test hundreds of fonts on directly?


but yeah over your own website is trickier

πŸ‘ 4

what would give true in this expression instead of "?" (if (instance? ? (js/Error 23)) ?



βœ”οΈ 4

but only if you use (js/Error. 23). construct new instance, not call it as a function.

paul a17:02:41

the end of this post says "Avoid using this for larger files since the results will become part of your build. Don’t include 5mb of text this way, load it at runtime instead."

paul a17:02:59

are there any idioms or patterns for doing that?


It means making an ajax request to your server.

paul a18:02:29

yeah, i was afraid you'd say that. i don't currently run my own server during tests, or if i am then i'm not aware of it.


If by "during tests" you mean "this web page runs tests", then you probably don't care about the web page size.

paul a19:02:05

yeah, i don't care about the size of the web page; or rather, i care that my tests are reasonably fast, but it won't bother me if the file is large and the tests are still fast


If you have to have 5MB of data to start running your tests, then it doesn't matter at all whether you embed it or make an AJAX request to get it. The blog post you linked fails to mention the reason for preferring AJAX - it's to improve the app loading time for better UX. For tests, you don't care about that at all.

paul a21:02:20

right on, thanks for your input


You probably do in order to serve your js

paul a18:02:09

yeah, that sounds true


is it possible to compile a single .cljs file into .js without setting up a src/ hierarchy?


I’ve used :paths [β€œ.”] before in clj projects. You could give that a shot


@dpsutton yep, that works.

parens 8