Skip to content

Commit 4a7585f

Browse files
authored
Add warning when deps clean fails (#13161)
1 parent aabe465 commit 4a7585f

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

lib/mix/lib/mix/tasks/deps.clean.ex

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ defmodule Mix.Tasks.Deps.Clean do
9999
paths
100100
end
101101

102+
defp maybe_warn_failed_file_deletion(results, dependency) when is_list(results) do
103+
messages =
104+
Enum.flat_map(results, fn
105+
{:error, reason, file} ->
106+
["\tfile: #{file}, reason: #{:file.format_error(reason)}"]
107+
108+
_ ->
109+
[]
110+
end)
111+
112+
with [_ | _] <- messages do
113+
Mix.shell().error(
114+
"warning: errors occurred while deleting files for dependency: #{dependency} \n" <>
115+
Enum.join(messages, "\n")
116+
)
117+
end
118+
end
119+
120+
defp maybe_warn_failed_file_deletion(result, dependency),
121+
do: maybe_warn_failed_file_deletion([result], dependency)
122+
102123
defp do_clean(apps, deps, build_path, deps_path, build_only?) do
103124
shell = Mix.shell()
104125

@@ -112,7 +133,8 @@ defmodule Mix.Tasks.Deps.Clean do
112133
|> Path.join(to_string(app))
113134
|> Path.wildcard()
114135
|> maybe_warn_for_invalid_path(app)
115-
|> Enum.each(&File.rm_rf!/1)
136+
|> Enum.map(&File.rm_rf/1)
137+
|> maybe_warn_failed_file_deletion(app)
116138

117139
# Remove everything from the source directory of dependencies.
118140
# Skip this step if --build option is specified or if
@@ -122,7 +144,8 @@ defmodule Mix.Tasks.Deps.Clean do
122144
else
123145
deps_path
124146
|> Path.join(to_string(app))
125-
|> File.rm_rf!()
147+
|> File.rm_rf()
148+
|> maybe_warn_failed_file_deletion(app)
126149
end
127150
end)
128151
end

0 commit comments

Comments
 (0)