From b93d4904a39fa5ef98ce56c342cde60a5e0296a0 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 6 Aug 2026 17:52:53 -0500 Subject: [PATCH] fix: handle missing :pending_batch_tasks assign in historical loader Use Map.get with default for all loading_generation and pending_batch_tasks socket.assigns accesses to prevent KeyError when key is not present. --- lib/aprsme_web/live/map_live/historical_loader.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aprsme_web/live/map_live/historical_loader.ex b/lib/aprsme_web/live/map_live/historical_loader.ex index 020b671..ea3efd0 100644 --- a/lib/aprsme_web/live/map_live/historical_loader.ex +++ b/lib/aprsme_web/live/map_live/historical_loader.ex @@ -113,7 +113,7 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do @spec cancel_pending_loads(Socket.t()) :: Socket.t() def cancel_pending_loads(socket) do # Cancel any pending batch load messages - Enum.each(socket.assigns.pending_batch_tasks, &Process.cancel_timer/1) + Enum.each(Map.get(socket.assigns, :pending_batch_tasks, []), &Process.cancel_timer/1) assign(socket, :pending_batch_tasks, []) end @@ -333,7 +333,7 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do generation = Map.get(socket.assigns, :loading_generation, 0) timer_ref = Process.send_after(self(), {:load_historical_batch, next_batch, generation}, 50) - assign(socket, :pending_batch_tasks, [timer_ref | socket.assigns.pending_batch_tasks]) + assign(socket, :pending_batch_tasks, [timer_ref | Map.get(socket.assigns, :pending_batch_tasks, [])]) end # Handle low zoom (heat map)