Ignoring in handle_info/2 is OK. Really?

Hi! The guides suggest a clause

def handle_info(_msg, state) do
  {:noreply, state}

to handle unexpected messages received by GenServer. But such ignoring can result in ignoring developers’ errors. So, I guess, there can be reasons to crash early on unexpected messages. Or - at least - log them. But not ignoring.

Please, show me where I’m wrong :slight_smile:


I agree with your point. I would expect to at least log unexpected messages. I suspect the guides’ point is to get people started with minimal tangents. OTP has certain “housekeeping” sorts of messages that come into handle_info that doesn’t make a lot of sense to explain to someone brand new to the framework, and that in many cases you really should just ignore, but I agree with the idea to log them. That way you’ll be aware of them and can start seeing what they mean when you run across them.

1 Like

Thanks for information! So, to be pedant :), we want to separate “housekeeping” messages from really not expected. Don’t we?

Btw, Elixir v1.4 will be moving towards to logging in such cases.


What is “such cases” at the context? All housekeeping messages, all unmatched messages, difference between the last and the former, or… what? :slight_smile:

Sorry. The default implementation for handle_info, which is the catch all
clause for unhandled messages will now log. If you provide your own
clauses, you need your own catch all and your own log though.


Aha, I see, thanks for the clarification! So, the default case will force a developer to notice “something else is happening”, and it is great. It is a motivation to recognize the reality…