Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an unreachable with/else code path #1642

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading