Fork me on GitHub
#clojurescript
<
2020-03-10
>
kwrooijen19:03:36

Hi, I'm currently running shadow-cljs but am having some trouble with reading exception messages (no idea of this is shadow-cljs related, just mentioning it) When my code hits the following line: (throw (ex-info (str "Some error") {:info 123} "This is the cause")) I get this error: But the {:info 123} and "This is the cause" is completely omitted.

kwrooijen19:03:10

However when I run this code in the REPL directly, I get the following error, with all the data intact:

kwrooijen19:03:59

Does anyone have an idea why all this extra info is missing?

darwin19:03:38

I think it is because the first case is printed by javascript. The second output is in your devtools console which presents values formatted with shadow-cljs custom formatter. You are throwing a clojurescript error, which is a javascript error with some extra clojurescript data attached. Under normal circumstances, this extra cljs data is presented only with the custom formatter - or you would have to do extra work to print it somehow.

darwin19:03:49

fyi. here is the implementation of devtools formatter installed by shadow-cljs: https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/cljs/devtools/client/console.cljs

thheller20:03:48

@U08E3BBST not sure why thats relevant 😛

darwin20:03:20

just as a proof that it is happening 🙂

thheller20:03:17

@UG9U7TPDZ the repl/invoke shadow-cljs error uses the console to log the error. the other one does not go through "log" and instead is handled by the default handler which just doesn't show the data

thheller20:03:41

@U08E3BBST but the console stuff in shadow-cljs doesn't have any formatter for errors 😛

thheller20:03:58

so there is no custom formatter handling that

😊 1
kwrooijen20:03:02

I see, so I need to add a formatter?

kwrooijen20:03:21

Or just something to handle logging?

thheller20:03:22

no, you need to catch the exception

thheller20:03:37

the actual exception object will have the data stuff

kwrooijen20:03:37

The exception is happening within a library, and it's printing it back with ex-info like I showed in the example code

kwrooijen20:03:59

But isn't ex-info meant to give me extra information?

thheller20:03:36

ex-info is for throwing exception with extra data

thheller20:03:42

ex-data is for getting that data

kwrooijen20:03:12

That makes sense, thanks.

mbarillier20:03:13

I've got a macro that works in clojure but not in clojurescript, wondering if I'm trying to do something that won't work because of macro differences. the macro generates a comparator based on a set of keys, e.g. (rec-comparator [:k1 :k2]) will expand to (fn [rec1# rec2#] (compare [(:k1 rec1#) (:k2 rec1#)] [(:k1 rec2#) (:k2 rec2#)])) (or something close to that). (sort (rec-comparator [:k1 :k2 :k3]) RECORDS) works in clj, but chokes in cljs, generating a compiler error: java.lang.IllegalArgumentException : Don't know how to create ISeq from: clojure.lang.Symbol .... do macros that generate functions work in clojurescript?

bfabry20:03:00

have you looked at the results of macroexpand for both cljs and clj?

mbarillier20:03:34

just did -- it's expanding to (fn* ([G__...1 G__...2] (compare ...))) ... extra set of parens looks weird, but this is my first attempt at a clojurescript macro

bfabry20:03:34

for the macro you're trying to create afaik it shouldn't look any different in clj vs cljs. the extra parens fn is valid syntax in both

thheller20:03:59

just a guess but how did you define the macro? looks like you defined it in CLJS. macros in CLJS need to be defined in CLJ, otherwise they are called as regular functions