fix: guard APRS send_message when disconnected

This commit is contained in:
Graham McIntire 2026-03-22 17:16:31 -05:00
parent 29da875a00
commit f840e8fd34
No known key found for this signature in database
2 changed files with 10 additions and 1 deletions

View file

@ -189,7 +189,10 @@ defmodule Aprsme.Is do
end
def send_message(message) do
GenServer.call(__MODULE__, {:send_message, message})
case Process.whereis(__MODULE__) do
nil -> {:error, :not_connected}
_pid -> GenServer.call(__MODULE__, {:send_message, message})
end
end
# Server methods

View file

@ -195,6 +195,12 @@ defmodule Aprsme.IsTest do
end
end
describe "send_message/1 when GenServer is not running" do
test "returns not_connected instead of crashing" do
assert Aprsme.Is.send_message("test message") == {:error, :not_connected}
end
end
describe "handle_info(:aprsme_no_message_timeout, ...)" do
test "ignores timeout when socket is nil" do
state = build_state(%{socket: nil})