Does IO.inspect work in handle_event?

I have a liveview with handle_events() that is trying to match against a map key in the parameters it receives. I’d like to debug or print out exactly what params are being passed into this event but IO.inspect does not appear to do anything. If I use IO.inspect anywhere else in my application it works, so I assume it has something to do with the fact that handle_events are callback from a separate process or something.

Any tips so I can see what my handle events is receiving?

1 Like

Please show your code.

It should be working, but maybe the clause is never matched. Or maybe You run a release?

I use IO.inspect all the time when debugging params…

3 Likes

maybe it’s just a typo in your post, but it’s handle_event not handle_events. If that typo’s in your code then your callback will never run and the process will always crash looking for handle_event

4 Likes

Uh, it was a typo. handle_event versus handle_events. thanks for the help, feel a bit dumb about that. :sheep:

2 Likes

It happens to everyone :slightly_smiling_face:

1 Like

FWIW, this is a situation where using @impl true on your LiveView callbacks would help - the compiler complains about typos:

warning: got "@impl true" for function handle_events/3 but no behaviour specifies such callback. The known callbacks are:

  * Phoenix.LiveView.handle_call/3 (function)
  * Phoenix.LiveView.handle_cast/2 (function)
  * Phoenix.LiveView.handle_event/3 (function)
  * Phoenix.LiveView.handle_info/2 (function)
  * Phoenix.LiveView.handle_params/3 (function)
  * Phoenix.LiveView.mount/3 (function)
  * Phoenix.LiveView.render/1 (function)
  * Phoenix.LiveView.terminate/2 (function)

  lib/yourapp_web/live/something_live.ex:49: YourappWeb.SomethingLive (module)
8 Likes