Improve error message for bad GenServer callback response?

601 views
Skip to first unread message

er...@scouten.com

unread,
Oct 23, 2016, 1:01:26 PM10/23/16
to elixir-lang-core
I recently wrote some bad code in a GenServer handle_cast callback. I forgot to add the {:noreply, new_state} clause at the end of that callback, so some random other value got returned.

Unfortunately (or fortunately?), the gap between writing the code and testing it (and thus finding this issue) included a break while I went out and enjoyed some adult beverages with some friends and then I came home and slept.

So when I got back to testing it this morning, the new code was not exactly top-of-mind 😅 and I had some challenges parsing this message:

09:43:47.772 [error] GenServer #PID<0.722.0> terminating
** (stop) bad return value: {:ok, #Reference<0.0.1.6782>}

Took me a while to figure out which GenServer was failing, where "bad return value" was coming from (thank you, GitHub code search), and which code of mine was triggering this error.

Perhaps the error could be extended to include at least the name of the offending module and callback name, something like:

09:43:47.772 [error] GenServer #PID<0.722.0> terminating
** (stop) bad return value {:ok, #Reference<0.0.1.6782>} in MyBorkedServer callback: handle_cast

Thanks!

-Eric

James Fish

unread,
Oct 23, 2016, 2:26:07 PM10/23/16
to elixir-l...@googlegroups.com
Hi Eric,

The error is from OTP's :gen_server so we can't improve the error in that way, at least in backwards compatible way. I think :gen_statem has a stacktrace in that situation, which is slightly better.

If you set Loggers level to debug you will see the message/state that caused the error.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/e5b458a6-9f01-4909-bf40-2988c2c2b89f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

er...@scouten.com

unread,
Oct 23, 2016, 4:47:44 PM10/23/16
to elixir-lang-core
OK, thanks.

-Eric
Reply all
Reply to author
Forward
0 new messages