Convert verification errors into diagnostics, closes #14768
This commit is contained in:
@@ -283,7 +283,21 @@ defmodule Module.ParallelChecker do
|
||||
|> emit_warnings(file, log?)
|
||||
|
||||
Enum.each(after_verify, fn {verify_mod, verify_fun} ->
|
||||
apply(verify_mod, verify_fun, [module])
|
||||
try do
|
||||
apply(verify_mod, verify_fun, [module])
|
||||
catch
|
||||
# We need to catch exceptions because files have already been written to disk,
|
||||
# so we need to convert verification errors into diagnostics by using IO.warn.
|
||||
kind, reason ->
|
||||
IO.warn(
|
||||
"exception happened while verifying module #{inspect(module)}\n\n" <>
|
||||
Exception.format(kind, reason, __STACKTRACE__),
|
||||
file: file,
|
||||
line: line,
|
||||
module: verify_mod,
|
||||
function: {verify_fun, 1}
|
||||
)
|
||||
end
|
||||
end)
|
||||
|
||||
diagnostics
|
||||
|
||||
@@ -1296,6 +1296,27 @@ defmodule Module.Types.IntegrationTest do
|
||||
|
||||
assert_warnings(files, warning)
|
||||
end
|
||||
|
||||
test "converts errors into diagnostics" do
|
||||
files = %{
|
||||
"a.ex" => """
|
||||
defmodule A do
|
||||
@after_verify __MODULE__
|
||||
|
||||
def __after_verify__(__MODULE__) do
|
||||
raise "oops"
|
||||
end
|
||||
end
|
||||
"""
|
||||
}
|
||||
|
||||
warning = [
|
||||
"warning: exception happened while verifying module A",
|
||||
"** (RuntimeError) oops"
|
||||
]
|
||||
|
||||
assert_warnings(files, warning)
|
||||
end
|
||||
end
|
||||
|
||||
describe "deprecated" do
|
||||
|
||||
Reference in New Issue
Block a user