Skip to content

Commit

Permalink
Fix an unreachable with/else code path (#1642)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshk authored Nov 18, 2024
1 parent b4c7ab6 commit 7ca6076
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion lib/nerves_hub/devices/metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ defmodule NervesHub.Devices.Metrics do
|> Map.merge(%{inserted_at: {:placeholder, :now}})
end)

Repo.insert_all(DeviceMetric, entries, placeholders: %{now: DateTime.utc_now()})
results = Repo.insert_all(DeviceMetric, entries, placeholders: %{now: DateTime.utc_now()})

case results do
{0, _} -> :error
{count, _} -> {:ok, count}
end
end

@doc """
Expand Down
6 changes: 3 additions & 3 deletions lib/nerves_hub_web/channels/device_channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,16 @@ defmodule NervesHubWeb.DeviceChannel do

with {:health_report, {:ok, _}} <-
{:health_report, Devices.save_device_health(device_health)},
{:metrics_report, {_, _}} <-
{:metrics_report, {:ok, _}} <-
{:metrics_report, Metrics.save_metrics(socket.assigns.device.id, metrics)} do
device_internal_broadcast!(socket, socket.assigns.device, "health_check_report", %{})
else
{:health_report, {:error, err}} ->
Logger.warning("Failed to save health check data: #{inspect(err)}")
log_to_sentry(socket.assigns.device, "[DeviceChannel] Failed to save health check data.")

{:metrics_report, {:error, err}} ->
Logger.warning("Failed to save metrics: #{inspect(err)}")
{:metrics_report, :error} ->
Logger.warning("Failed to save metrics")
log_to_sentry(socket.assigns.device, "[DeviceChannel] Failed to save metrics.")
end

Expand Down
2 changes: 1 addition & 1 deletion test/nerves_hub/device_metrics_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule NervesHub.DeviceMetricsTest do
"used_percent" => 2
}

assert {7, nil} = Metrics.save_metrics(device.id, metrics)
assert {:ok, 7} = Metrics.save_metrics(device.id, metrics)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/nerves_hub_web/live/devices/health_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule NervesHubWeb.Devices.HealthTest do
"used_percent" => 2
}

assert {7, nil} = Metrics.save_metrics(device.id, metrics)
assert {:ok, 7} = Metrics.save_metrics(device.id, metrics)

conn
|> visit("/org/#{org.name}/#{product.name}/devices/#{device.identifier}/health")
Expand Down
4 changes: 2 additions & 2 deletions test/nerves_hub_web/live/devices/show_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ defmodule NervesHubWeb.Live.Devices.ShowTest do
"used_percent" => 60
}

assert {7, nil} = Metrics.save_metrics(device.id, metrics)
assert {:ok, 7} = Metrics.save_metrics(device.id, metrics)

conn
|> visit("/org/#{org.name}/#{product.name}/devices/#{device.identifier}")
Expand Down Expand Up @@ -279,7 +279,7 @@ defmodule NervesHubWeb.Live.Devices.ShowTest do
"used_percent" => 60
}

assert {6, nil} = Metrics.save_metrics(device.id, metrics)
assert {:ok, 6} = Metrics.save_metrics(device.id, metrics)

conn
|> visit("/org/#{org.name}/#{product.name}/devices/#{device.identifier}")
Expand Down

0 comments on commit 7ca6076

Please sign in to comment.