Skip to content

Commit 2dc3d27

Browse files
committed
Convert verification errors into diagnostics, closes #14768
1 parent 59c0a38 commit 2dc3d27

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

lib/elixir/lib/module/parallel_checker.ex

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,21 @@ defmodule Module.ParallelChecker do
283283
|> emit_warnings(file, log?)
284284

285285
Enum.each(after_verify, fn {verify_mod, verify_fun} ->
286-
apply(verify_mod, verify_fun, [module])
286+
try do
287+
apply(verify_mod, verify_fun, [module])
288+
catch
289+
# We need to catch exceptions because files have already been written to disk,
290+
# so we need to convert verification errors into diagnostics by using IO.warn.
291+
kind, reason ->
292+
IO.warn(
293+
"exception happened while verifying module #{inspect(module)}\n\n" <>
294+
Exception.format(kind, reason, __STACKTRACE__),
295+
file: file,
296+
line: line,
297+
module: verify_mod,
298+
function: {verify_fun, 1}
299+
)
300+
end
287301
end)
288302

289303
diagnostics

lib/elixir/test/elixir/module/types/integration_test.exs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,27 @@ defmodule Module.Types.IntegrationTest do
12961296

12971297
assert_warnings(files, warning)
12981298
end
1299+
1300+
test "converts errors into diagnostics" do
1301+
files = %{
1302+
"a.ex" => """
1303+
defmodule A do
1304+
@after_verify __MODULE__
1305+
1306+
def __after_verify__(__MODULE__) do
1307+
raise "oops"
1308+
end
1309+
end
1310+
"""
1311+
}
1312+
1313+
warning = [
1314+
"warning: exception happened while verifying module A",
1315+
"** (RuntimeError) oops"
1316+
]
1317+
1318+
assert_warnings(files, warning)
1319+
end
12991320
end
13001321

13011322
describe "deprecated" do

0 commit comments

Comments
 (0)