taoensso / sente

Realtime web comms library for Clojure/Script
https://www.taoensso.com/sente
Eclipse Public License 1.0
1.74k stars 193 forks source link

Cryptic invalid event error when using `chsk-send!` on the client side. #416

Closed kovasap closed 1 year ago

kovasap commented 1 year ago

I'm getting the following error in my browser console when making this call: (chsk-send! [:testing {:my "data"}] 5000 (fn [cb-reply] (prn "yes"))). Is there any way this error message could be made more informative? As a new sente user I'm having a really hard time trying to determine what's wrong with my chsk-send! call.

Error: Invalid event
    at new cljs$core$ExceptionInfo (http://localhost:3000/js/compiled/cljs-runtime/cljs.core.js:37370:10)
    at Function.eval [as cljs$core$IFn$_invoke$arity$3] (http://localhost:3000/js/compiled/cljs-runtime/cljs.core.js:37431:9)
    at Function.eval [as cljs$core$IFn$_invoke$arity$2] (http://localhost:3000/js/compiled/cljs-runtime/cljs.core.js:37427:26)
    at Object.taoensso$sente$assert_event [as assert_event] (http://localhost:3000/js/compiled/cljs-runtime/taoensso.sente.js:58:25)
    at Object.taoensso$sente$assert_send_args [as assert_send_args] (http://localhost:3000/js/compiled/cljs-runtime/taoensso.sente.js:3024:16)
    at Object.eval [as taoensso$sente$IChSocket$_chsk_send_BANG_$arity$3] (http://localhost:3000/js/compiled/cljs-runtime/taoensso.sente.js:3788:24)
    at Object.taoensso$sente$_chsk_send_BANG_ [as _chsk_send_BANG_] (http://localhost:3000/js/compiled/cljs-runtime/taoensso.sente.js:2947:13)
    at Object.eval [as taoensso$sente$IChSocket$_chsk_send_BANG_$arity$3] (http://localhost:3000/js/compiled/cljs-runtime/taoensso.sente.js:5166:23)
    at Object.taoensso$sente$_chsk_send_BANG_ [as _chsk_send_BANG_] (http://localhost:3000/js/compiled/cljs-runtime/taoensso.sente.js:2947:13)
    at Function.eval [as cljs$core$IFn$_invoke$arity$3] (http://localhost:3000/js/compiled/cljs-runtime/taoensso.sente.js:3006:23)
ptaoussanis commented 1 year ago

Hi Kovas!

I'm getting the following error in my browser console when making this call

It looks like your event-id keyword needs to be namespaced, so something like :my/testing. The README (see <ev-id> form) and reference example show examples that should work.

Here is the code that validates events.

I'd encourage you to try start with the reference example and confirm that you can get that working as expected. Then you can adapt it as needed, or use it as a point of comparison.

Is there any way this error message could be made more informative?

The error thrown is an ex-info type which should include detailed information about the cause of the problem.

How are you logging errors? It's possible that your logging tool/config is set to not include this information. The reference example shows how to use Timbre, which should include this info by default. (I don't recall for sure, but you might need to check that you're using a recent version of Timbre (latest is [com.taoensso/timbre "6.0.4"]).

The current Sente reference example dependencies are a little out of date, am planning to update then when I next do some batched work on Sente.

Hope that helps?

kovasap commented 1 year ago

Yep, that was it! It would be cool if this could be surfaced somehow in the error message. My current logging setup didn't catch it; I'll make a note to look into this.

ptaoussanis commented 1 year ago

It would be cool if this could be surfaced somehow in the error message.

As I showed above, the exception here already contains detailed information in the form of data (ex-data). This is quite typical/idiomatic for modern Clojure exceptions (since the advent of ex-info in Clojure v1.4), and this has a lot of benefits.

Rather than try to duplicate/cram info into the error message string, these kinds of exceptions are a lot more expressive (support arbitrary rich data) and are much easier to work with programmatically since the error consumer can directly access relevant data for filtering, logging, and other tooling, etc.

Most (all?) logging tools developed with Clojure in mind should automatically float this attached data. As mentioned earlier, I'd encourage you to adopt such a tool since you'll otherwise keep running into the same problem - Sente's errors are not unique in this respect.

Hope that helps!