Trying to make a drab stream demo using hub but getting errors

Im trying to redo the server sent events example from drab using hub but im getting the following error when connection to the page that should render all events.

[error] Drab Handler failed with the following exception:
** (Protocol.UndefinedError) protocol Enumerable not implemented for nil. This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Floki.HTMLTree, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet,Postgrex.Stream, Range, Stream
    (elixir) /private/tmp/elixir-20180620-82402-14wughj/elixir-1.6.6/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir) /private/tmp/elixir-20180620-82402-14wughj/elixir-1.6.6/lib/elixir/lib/enum.ex:141: Enumerable.reduce/3
    (elixir) lib/enum.ex:1919: Enum.reduce/3
    (drab) lib/drab/live.ex:968: Drab.Live.decrypted_assigns/1
    (drab) lib/drab/live.ex:958: Drab.Live.decrypted_from_browser/1
    (drab) lib/drab/live.ex:918: Drab.Live.assigns_and_nodrab/1
    (drab) lib/drab/live.ex:574: Drab.Live.do_poke/5
    (streamdemo) lib/streamdemo_web/commanders/gen_commander.ex:18: StreamdemoWeb.GenCommander.handle_event/1
    (drab) lib/drab.ex:286: anonymous fn/3 in Drab.handle_callback/3

This is the code that throws the exception.

defmodule StreamdemoWeb.GenCommander do
  use Drab.Commander
  require Hub
  require Logger
  onconnect :connected

  def connected(socket) do
    sub = Hub.subscribe("channel", _)
    Logger.debug("Connected and subscribed #{inspect sub}")

  defp handle_event(socket) do
    receive do
      %{age: age, name: name} = msg  ->
      |> IO.inspect()
      |> poke(genevent: "dd")

The code is working. The error was that I had not named the template .drab

1 Like

Could you please open an issue on github? Drab should show the better error explanation than that in such case.

1 Like

Github issue opened at issues.