From 9509c4942971ac1f7c8fb08b17dc6edcf9f73c9c Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 25 Oct 2025 12:48:34 -0500 Subject: [PATCH] Fix mobile channel update_bounds nil handling Replace 'with' clause that was failing when socket.assigns[:subscribed] returned nil. Now properly checks subscription status using Map.get with a default value of false to prevent WithClauseError. Fixes error: no with clause matching: nil Generated with Claude Code https://claude.com/claude-code --- lib/aprsme_web/channels/mobile_channel.ex | 42 ++++++++++++----------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/aprsme_web/channels/mobile_channel.ex b/lib/aprsme_web/channels/mobile_channel.ex index e7ede07..dc3f07d 100644 --- a/lib/aprsme_web/channels/mobile_channel.ex +++ b/lib/aprsme_web/channels/mobile_channel.ex @@ -102,28 +102,30 @@ defmodule AprsmeWeb.MobileChannel do west: ensure_float(west) } - # Validate bounds - with :ok <- validate_bounds(bounds), - true <- socket.assigns[:subscribed] do - # Unsubscribe from old bounds - if socket.assigns[:bounds] do - Aprsme.StreamingPacketsPubSub.unsubscribe_from_bounds(self(), socket.assigns.bounds) + # Check if subscribed + if Map.get(socket.assigns, :subscribed, false) do + # Validate bounds + case validate_bounds(bounds) do + :ok -> + # Unsubscribe from old bounds + if socket.assigns[:bounds] do + Aprsme.StreamingPacketsPubSub.unsubscribe_from_bounds(self(), socket.assigns.bounds) + end + + # Subscribe to new bounds + Aprsme.StreamingPacketsPubSub.subscribe_to_bounds(self(), bounds) + + socket = assign(socket, :bounds, bounds) + + Logger.debug("Mobile client #{socket.assigns.client_id} updated bounds: #{inspect(bounds)}") + + {:reply, {:ok, %{bounds: bounds, message: "Bounds updated"}}, socket} + + {:error, reason} -> + {:reply, {:error, %{message: reason}}, socket} end - - # Subscribe to new bounds - Aprsme.StreamingPacketsPubSub.subscribe_to_bounds(self(), bounds) - - socket = assign(socket, :bounds, bounds) - - Logger.debug("Mobile client #{socket.assigns.client_id} updated bounds: #{inspect(bounds)}") - - {:reply, {:ok, %{bounds: bounds, message: "Bounds updated"}}, socket} else - {:error, reason} -> - {:reply, {:error, %{message: reason}}, socket} - - false -> - {:reply, {:error, %{message: "Not subscribed. Call subscribe_bounds first."}}, socket} + {:reply, {:error, %{message: "Not subscribed. Call subscribe_bounds first."}}, socket} end end