Skip to content

Commit

Permalink
Improve error handling of allProjectsByFunction (#4483)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIvanoff authored Nov 21, 2024
1 parent 4a990fa commit 870c7a9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/sanbase/project/list/selector/project_list_selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ defmodule Sanbase.Project.ListSelector do
filters_combinator = Transform.args_to_filters_combinator(args)
include_hidden = Map.get(args, :include_hidden, false)

base_slugs = base_slugs(base_projects_selector)

with {:ok, included_slugs} <- included_slugs_by_filters(filters, filters_combinator),
with {:ok, base_slugs} <- base_slugs(base_projects_selector),
{:ok, included_slugs} <- included_slugs_by_filters(filters, filters_combinator),
included_slugs = intersect_with_base_slugs(included_slugs, base_slugs),
included_slugs = remove_hidden_slugs(included_slugs),
{:ok, ordered_slugs} <- ordered_slugs_by_order_by(order_by, included_slugs) do
Expand Down Expand Up @@ -197,21 +196,24 @@ defmodule Sanbase.Project.ListSelector do
end
end

defp base_slugs(:all), do: :all
defp base_slugs(:all), do: {:ok, :all}

defp base_slugs(args_list) do
Enum.flat_map(args_list, fn args ->
defp base_slugs(args_list) when is_list(args_list) do
Enum.reduce_while(args_list, {:ok, []}, fn args, {:ok, acc} ->
case get_base_slugs(args) do
{:ok, slugs} -> slugs
{:error, error} -> raise(error)
{:ok, slugs} -> {:cont, {:ok, slugs ++ acc}}
{:error, error} -> {:halt, {:error, error}}
end
end)
end

defp get_base_slugs(%{watchlist_id: id} = map) do
detect_cycles!(map)

id |> Sanbase.UserList.by_id!([]) |> Sanbase.UserList.get_slugs()
case Sanbase.UserList.by_id(id, []) do
{:ok, watchlist} -> Sanbase.UserList.get_slugs(watchlist)
{:error, error} -> {:error, error}
end
end

defp get_base_slugs(%{watchlist_slug: slug} = map) do
Expand Down

0 comments on commit 870c7a9

Please sign in to comment.