Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handle_cast fake return value #296

Merged
merged 1 commit into from
Jul 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions lib/kafka_ex/gen_consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -285,49 +285,56 @@ defmodule KafkaEx.GenConsumer do

def handle_call(msg, _from, consumer_state) do
# taken from the GenServer handle_call implementation
proc = case Process.info(self(), :registered_name) do
{_, []} -> self()
{_, name} -> name
end
proc =
case Process.info(self(), :registered_name) do
{_, []} -> self()
{_, name} -> name
end

# We do this to trick Dialyzer to not complain about non-local returns.
case :erlang.phash2(1, 1) do
0 ->
raise "attempted to call KafkaEx.GenConsumer #{inspect proc} " <>
"but no handle_call/3 clause was provided"
1 -> {:reply, {:bad_call, msg}, consumer_state}
raise "attempted to call KafkaEx.GenConsumer #{inspect(proc)} " <>
"but no handle_call/3 clause was provided"

1 ->
{:reply, {:bad_call, msg}, consumer_state}
end
end

def handle_cast(msg, consumer_state) do
# taken from the GenServer handle_cast implementation
proc = case Process.info(self(), :registered_name) do
{_, []} -> self()
{_, name} -> name
end
proc =
case Process.info(self(), :registered_name) do
{_, []} -> self()
{_, name} -> name
end

# We do this to trick Dialyzer to not complain about non-local returns.
case :erlang.phash2(1, 1) do
0 ->
raise "attempted to cast KafkaEx.GenConsumer #{inspect(proc)} " <>
" but no handle_cast/2 clause was provided"
1 -> {:noreply, {:bad_cast, msg}, consumer_state}
" but no handle_cast/2 clause was provided"

1 ->
{:noreply, consumer_state}
end
end

def handle_info(msg, consumer_state) do
# taken from the GenServer handle_info implementation
proc = case Process.info(self(), :registered_name) do
{_, []} -> self()
{_, name} -> name
end
proc =
case Process.info(self(), :registered_name) do
{_, []} -> self()
{_, name} -> name
end

pattern = '~p ~p received unexpected message in handle_info/2: ~p~n'
:error_logger.error_msg(pattern, [__MODULE__, proc, msg])
{:noreply, consumer_state}
end

defoverridable [init: 2, handle_call: 3, handle_cast: 2, handle_info: 2]
defoverridable init: 2, handle_call: 3, handle_cast: 2, handle_info: 2
end
end

Expand Down