Skip to content

Commit dbcde1b

Browse files
Fix error message when a version is locked (#530)
This was previously providing a fairly cryptic message suggesting the version wasn't installed, we should instead explain explicitly its locked and how to unlock it
1 parent ad0c65b commit dbcde1b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

apps/core/lib/core/services/dependencies.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ defmodule Core.Services.Dependencies do
1515
@spec valid?(Dependencies.t | Dependencies.Dependency.t | nil, User.t) :: boolean
1616
def valid?(nil, _), do: true
1717
def valid?(%Dependencies{dependencies: nil}, _), do: true
18-
def valid?(%Dependencies{dependencies: deps}, user) when is_list(deps),
19-
do: Enum.all?(deps, &valid?(&1, user))
18+
def valid?(%Dependencies{dependencies: []}, _), do: true
19+
def valid?(%Dependencies{dependencies: [dep | deps]} = dependency, user) do
20+
case valid?(dep, user) do
21+
{:locked, _} = locked -> locked
22+
false -> false
23+
_ -> valid?(%{dependency | dependencies: deps}, user)
24+
end
25+
end
2026
def valid?(%Dependencies.Dependency{type: :terraform, repo: repo} = dep, %User{id: user_id}) do
2127
TerraformInstallation.for_repo_name(repo)
2228
|> TerraformInstallation.for_terraform_name(find_names(dep))
@@ -58,6 +64,7 @@ defmodule Core.Services.Dependencies do
5864
def validate([dep | rest], user) do
5965
case valid?(dep, user) do
6066
true -> validate(rest, user)
67+
{:locked, repo} -> {:error, "you have a pending breaking change, apply it locally then run `plural repos unlock #{repo}` to allow future installs"}
6168
false -> {:error, {:missing_dep, dep}}
6269
end
6370
end
@@ -92,7 +99,7 @@ defmodule Core.Services.Dependencies do
9299
def closure(nil), do: []
93100
def closure(deps) when is_list(deps), do: closure(deps, MapSet.new(), [])
94101

95-
defp valid_version?([%{locked: true} | _], _), do: false # don't deliver updates when an installation is locked
102+
defp valid_version?([%{locked: true} | _], %{repo: repo}), do: {:locked, repo} # don't deliver updates when an installation is locked
96103
defp valid_version?([_ | _], %{version: nil}), do: true
97104
defp valid_version?(versions, %{any_of: [_ | _] = deps}) do
98105
by_name = Enum.into(deps, %{}, & {&1.name, &1})

apps/core/test/services/dependencies_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule Core.Services.DependenciesTest do
2424
assert Dependencies.valid?(terraform.dependencies, user)
2525
end
2626

27-
test "If a dependency is locked, it will return false" do
27+
test "If a dependency is locked, it will return a locked tuple" do
2828
chart = insert(:chart)
2929
terraform = insert(:terraform)
3030
user = insert(:user)
@@ -43,7 +43,7 @@ defmodule Core.Services.DependenciesTest do
4343
%{type: :terraform, repo: terraform.repository.name, name: terraform.name}
4444
]})
4545

46-
refute Dependencies.valid?(terraform.dependencies, user)
46+
{:locked, _} = Dependencies.valid?(terraform.dependencies, user)
4747
end
4848

4949
test "If a dependency is missing it returns false" do

0 commit comments

Comments
 (0)