Dynamic channel topics with Phoenix

Hi all,

I’m having a problem which I cannot manage to solve on my own with phoenix channels. Specifically about channels with dynamic topics.

Given that I have the following channel setup:

channel "organization:*", TestWeb.OrganizationChannel

I want to connect on different channels based on dynamic ids passed as topics from the client. Based on a solution I found on an older post I did the following bit:

@impl true
  def join(
       "organization:" <> organization_id,
      ) do
    # some logic here

    Logger.debug("ORG ID -> ", organization_id)

    send(self(), :after_join)
    {:ok, socket}

Everytime I connect to this channel with a topic string that looks like organization:4f1665fa-05d2-450a-bfbd-d105ebb00ede I receive the following error:

** (Protocol.UndefinedError) protocol Enumerable not implemented for "4f1665fa-05d2-450a-bfbd-d105ebb00ede" of type BitString

If I just run in iex “organization:” <> id = “organization:123”, the pattern matches ok. What am I missing here? Is there something special with the join handler?

Thanks in advance and I’m happy to join your community.

Hey @acalinica the issue relatively straightforwardly is your Logger.debug call. Logger — Logger v1.16.1 The arguments to Logger.debug are msg and opts so you’re passing in organization_id where it expects options.

To fix simply:

Logger.debug("ORG ID -> #{inspect(organization_id)}")

For me personally when I’m just doing this sort of development logging I just use Kernel — Elixir v1.16.1 so you can just dbg(organization_id)


You beat me by 10 seconds. Kudos. Or I am getting old.

1 Like

Wow, Logger was probably the last place to look in. Thanks for the quick answers. I wish I had asked this 8 hours ago. :sweat_smile:

Did you not have “file_name.ex:1234” at the left? I.e. a code location where the error is?

Now that you’re saying, I see that the error indicates the line number of the Logger.