This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-20
Channels
- # announcements (42)
- # babashka (70)
- # beginners (152)
- # chlorine-clover (19)
- # cider (14)
- # clj-kondo (23)
- # clojars (15)
- # clojure (86)
- # clojure-denmark (1)
- # clojure-dev (5)
- # clojure-europe (57)
- # clojure-france (145)
- # clojure-hungary (2)
- # clojure-italy (5)
- # clojure-nl (7)
- # clojure-spec (35)
- # clojure-sweden (2)
- # clojure-uk (58)
- # clojurebridge (1)
- # clojured (1)
- # clojurescript (50)
- # core-typed (9)
- # cursive (10)
- # data-science (11)
- # datascript (4)
- # datomic (25)
- # emacs (8)
- # fulcro (49)
- # graalvm (7)
- # graphql (6)
- # joker (1)
- # juxt (2)
- # kaocha (1)
- # off-topic (22)
- # other-lisps (1)
- # pathom (20)
- # re-frame (3)
- # reagent (11)
- # reitit (2)
- # remote-jobs (1)
- # shadow-cljs (44)
- # spacemacs (2)
- # sql (17)
- # tree-sitter (2)
- # vim (8)
- # vrac (2)
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...
@stebokas what would you possibly deserialize it to on the other end? I would strongly suggest keeping exceptions out of your data
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)))
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...
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.
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.
Personally, I don't see any argument against just iterating over getOwnPropertyNames
and not even thinking about the particular fields.
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 ( 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.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
@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
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)
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
I bet react hooks had something for this, they are pretty keen on dev tools built on it
no i mean you can test hundreds of fonts on http://fonts.google.com directly?
what would give true in this expression instead of "?" (if (instance? ? (js/Error 23))
?
but only if you use (js/Error. 23)
. construct new instance, not call it as a function.
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
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.
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.