Fork me on GitHub
#clojurescript
<
2020-02-20
>
Old account08:02:25

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...

p-himik10:02:55

I replied on SO.

βœ”οΈ 4
thheller09:02:06

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

p-himik10:02:32

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

Old account10:02:57

yes this is for logging

thheller10:02:46

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)))

p-himik10:02:10

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

Old account10:02:26

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

p-himik10:02:43

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

Old account10:02:44

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

thheller10:02:51

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

thheller10:02:24

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

p-himik10:02:33

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

p-himik10:02:25

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

βœ”οΈ 4
thheller10:02:08

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

πŸ‘ 4
thheller10:02:15

thats pretty much the only thing you get

thheller10:02:20

both are strings

p-himik10:02:02

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 err.data = ['this', 'and', 'that']. It may be useful to not lose that information.

p-himik10:02:42

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

πŸ‘ 4
thheller10:02:36

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

p-himik11:02:52

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.

Frederik10:02:49

Hi, I'm trying to set up a clojure script environment with figwheel. Going through figwheel's quick -start ( https://github.com/bhauman/lein-figwheel/wiki/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: https://github.com/bhauman/figwheel-main/issues/128 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 https://github.com/yogthos/mastodon-bot, unfortunately it uses an old mastodon library that seems to be abandoned. I'm currently looking at this https://github.com/neet/masto.js, 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 https://github.com/neet/masto.js/blob/master/examples/create-new-status-with-image.ts

penryu01:02:00

@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.

penryu01:02:04

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.

penryu01:02:52

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

penryu01:02:52

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
  ls.cljs
  $

vemv12:02:18

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)

thheller12:02:03

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

vemv12:02:33

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

p-himik12:02:00

That sounds useful.

dominicm12:02:46

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

πŸ‘€ 4
thheller12:02:55

no i mean you can test hundreds of fonts on http://fonts.google.com directly?

thheller13:02:08

but yeah over your own website is trickier

πŸ‘ 4
Old account14:02:42

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

thheller14:02:04

js/Error

βœ”οΈ 4
thheller14:02:41

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." https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745

paul a17:02:59

are there any idioms or patterns for doing that?

dominicm17:02:17

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.

p-himik19:02:00

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

p-himik19:02:27

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

dominicm18:02:40

You probably do in order to serve your js

paul a18:02:09

yeah, that sounds true

erik18:02:27

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

dpsutton19:02:42

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

erik19:02:18

@dpsutton yep, that works.

parens 8