fix: remove unreachable error clauses causing compile warnings
Fixed three compile warnings by removing unreachable error handling:
1. Dynamic.discover_sensors/2 always returns {:ok, sensors}, never errors
- Removed unreachable error clause in discovery.ex
- Updated spec to reflect actual return type
2. parse_detection_rule/2 always returns {:ok, :processed}
- Simplified create_detection_rules/2 to use Enum.each instead of reduce_while
- Removed unreachable error handling in caller
3. import_all_from_directory/2 always returns {:ok, %{...}}
- Removed unreachable error clause in Mix task
- Simplified to direct pattern match
All code now compiles without warnings.
This commit is contained in:
parent
888a1e0dda
commit
143d9dceb3
4 changed files with 14 additions and 28 deletions
|
|
@ -122,15 +122,10 @@ defmodule Mix.Tasks.ImportProfiles do
|
|||
Mix.shell().info("Importing all profiles from: #{librenms_path}")
|
||||
Mix.shell().info("This may take several minutes...")
|
||||
|
||||
case Importer.import_all_from_directory(detection_dir, discovery_dir) do
|
||||
{:ok, stats} ->
|
||||
Mix.shell().info("\nImport complete!")
|
||||
Mix.shell().info("Successfully imported: #{stats.success} profiles")
|
||||
Mix.shell().info("Failed to import: #{stats.failed} profiles")
|
||||
|
||||
{:error, reason} ->
|
||||
Mix.shell().error("Failed to import profiles: #{inspect(reason)}")
|
||||
end
|
||||
{:ok, stats} = Importer.import_all_from_directory(detection_dir, discovery_dir)
|
||||
Mix.shell().info("\nImport complete!")
|
||||
Mix.shell().info("Successfully imported: #{stats.success} profiles")
|
||||
Mix.shell().info("Failed to import: #{stats.failed} profiles")
|
||||
else
|
||||
Mix.shell().error("external path not found. Use --librenms-path option.")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -97,10 +97,8 @@ defmodule Towerops.DeviceProfiles.Importer do
|
|||
case DeviceProfiles.create_profile(attrs) do
|
||||
{:ok, profile} ->
|
||||
# Create detection rules
|
||||
case create_detection_rules(profile.id, data["discovery"] || []) do
|
||||
:ok -> {:ok, profile}
|
||||
{:error, _} = error -> error
|
||||
end
|
||||
:ok = create_detection_rules(profile.id, data["discovery"] || [])
|
||||
{:ok, profile}
|
||||
|
||||
{:error, _} = error ->
|
||||
error
|
||||
|
|
@ -108,12 +106,11 @@ defmodule Towerops.DeviceProfiles.Importer do
|
|||
end
|
||||
|
||||
defp create_detection_rules(profile_id, rules) when is_list(rules) do
|
||||
Enum.reduce_while(rules, :ok, fn rule, _acc ->
|
||||
case parse_detection_rule(profile_id, rule) do
|
||||
{:ok, _} -> {:cont, :ok}
|
||||
{:error, _} = error -> {:halt, error}
|
||||
end
|
||||
Enum.each(rules, fn rule ->
|
||||
parse_detection_rule(profile_id, rule)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
defp parse_detection_rule(profile_id, rule) do
|
||||
|
|
|
|||
|
|
@ -301,15 +301,9 @@ defmodule Towerops.Snmp.Discovery do
|
|||
|
||||
@spec discover_sensors(Client.connection_opts(), profile()) :: {:ok, [sensor_data()]}
|
||||
defp discover_sensors(client_opts, {:dynamic, profile}) do
|
||||
case Dynamic.discover_sensors(profile, client_opts) do
|
||||
{:ok, sensors} ->
|
||||
Logger.debug("Discovered #{length(sensors)} sensors")
|
||||
{:ok, sensors}
|
||||
|
||||
{:error, _} ->
|
||||
Logger.warning("Sensor discovery failed, continuing without sensors")
|
||||
{:ok, []}
|
||||
end
|
||||
{:ok, sensors} = Dynamic.discover_sensors(profile, client_opts)
|
||||
Logger.debug("Discovered #{length(sensors)} sensors")
|
||||
{:ok, sensors}
|
||||
end
|
||||
|
||||
defp discover_sensors(client_opts, profile) when is_atom(profile) do
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ defmodule Towerops.Snmp.Profiles.Dynamic do
|
|||
Walks SNMP OIDs defined in the profile's sensor_definitions.
|
||||
"""
|
||||
@spec discover_sensors(DeviceProfile.t(), Client.connection_opts()) ::
|
||||
{:ok, [Discovery.sensor_data()]} | {:error, term()}
|
||||
{:ok, [Discovery.sensor_data()]}
|
||||
def discover_sensors(profile, client_opts) do
|
||||
# Load profile with sensor definitions
|
||||
profile = DeviceProfiles.get_profile_with_associations(profile.os)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue