From a52f5a864448fcf55eca769b4091bd02bde2e6f6 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 10 Mar 2026 13:57:49 -0500 Subject: [PATCH] fix: handle nil SNMP community string in discovery logging - Check if community string is nil before slicing - Display '(none)' instead of crashing with FunctionClauseError - Fixes discovery crashes when community string is not set Error was: String.slice(nil, 0..3) causing discovery tasks to fail --- lib/towerops/snmp/deferred_discovery.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/towerops/snmp/deferred_discovery.ex b/lib/towerops/snmp/deferred_discovery.ex index 807a0d7b..516e3f95 100644 --- a/lib/towerops/snmp/deferred_discovery.ex +++ b/lib/towerops/snmp/deferred_discovery.ex @@ -181,12 +181,18 @@ defmodule Towerops.Snmp.DeferredDiscovery do port = Keyword.get(client_opts, :port, 161) adapter = Keyword.get(client_opts, :adapter, "Real SNMP") + # Safely format community string (may be nil) + community_display = + if community && String.length(community) > 0, + do: String.slice(community, 0..3) <> "***", + else: "(none)" + Logger.warning( "Device #{ip} categorized as unresponsive - SNMP GET failed", ip: ip, port: port, version: version, - community: String.slice(community, 0..3) <> "***", + community: community_display, adapter: inspect(adapter), error: inspect(reason) )