astarte-platform / astarte

Core Astarte Repository
https://docs.astarte-platform.org/
Apache License 2.0
238 stars 46 forks source link

Wrong pat match failed `DatabaseQuery.call` #917

Open shinnokdisengir opened 5 months ago

shinnokdisengir commented 5 months ago

Description

Some DatabaseQuery.call failure pattern matching never match. The function always returns {:error, _} when it fails.

Expected Behavior

with {:ok, _result} <- DatabaseQuery.call(client, batch) do
  :ok
else
  {:error, reason} ->
    error_message =
      case reason do
        %{acc: _, msg: error_msg} -> error_msg
        _ -> inspect(reason)
      end

    Logger.warning("Failed batch due to database error: #{error_message}.", tag: "db_error")
    {:error, :database_error}
end

Current Behavior

see here: https://github.com/astarte-platform/astarte/blob/c335319e11dc0c0d8b0b28e8a36b26af33f5fc60/apps/astarte_realm_management/lib/astarte_realm_management/queries.ex#L168 https://github.com/astarte-platform/astarte/blob/c335319e11dc0c0d8b0b28e8a36b26af33f5fc60/apps/astarte_realm_management/lib/astarte_realm_management/queries.ex#L194