I’ve cleaned the IO.puts out of the pasted code.
def next_phase(state, player, opponent) do
current = state["status"]["phase"]
ind = Enum.find_index(turn_sequence(), fn(x) -> x == current end)
next = Enum.at(turn_sequence(), Enum.at(turn_sequence_indexes(), ind))
state =
case state["status"]["player_turn"] == player do
true ->
case state[opponent]["stops_opponent"][current] do
true ->
# this is where the error is happening, inside this clause, the last IO.puts is actually here instead of this comment
state
|> put_in([player, "on_play"], false)
|> put_in([opponent, "on_play"], true)
|> set_stack_passing(player, opponent, current, next)
|> set_timers(player, opponent)
|> prepare_broadcast("passing")
false ->
state
|> put_in(["status", "phase"], next)
|> refresh_current_timer(player)
|> prepare_broadcast("pass-enter")
case state[player]["stops_self"][next] do
true ->
{:ok}
false ->
state
|> pass(player, state[player]["id"])
end
end
false ->
state
|> put_in([player, "on_play"], false)
|> put_in([opponent, "on_play"], true)
|> put_in(["status", "phase"], next)
|> set_timers(player, opponent)
case state[opponent]["stops_self"][next] do
true ->
state
|> prepare_broadcast("enters")
false ->
state
|> pass(opponent, state[opponent]["id"])
end
end
end
So if I have the IO.puts statements to see the chain, I get this on the console:
inside pass
inside active_player
23
true
false
inside active_player true
inside pass_stack
nil
inside nil pass stack
#these are the logs referring to that method
inside true player_turn main
player_1
inside true player_turn, true opponent stops current
Then it crashes with:
[error] GenServer #PID<0.999.0> terminating
** (WithClauseError) no with clause matching: %{"game_id" => 5, "messages" => ["mofo is passing to the main phase"], "player_1" .... I've truncated this, but it's basically the game state
I thought it might have something to do with the state=
assignment, but I’ve removed it and it throws the same error. I can see that the piping goes to prepare_broadcast() because a message is added to the “messages” key.
Can anybody see something wrong with my case...do
? Thanks