Skip to content

Commit c6c4b04

Browse files
committed
Fix formatting call_intersect error
1 parent a313549 commit c6c4b04

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

lib/gradient/elixir_expr.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ defmodule Gradient.ElixirExpr do
5555
"\'" <> List.to_string(charlist) <> "\'"
5656
end
5757

58+
def pp_expr({:remote, _, _, _} = remote_name) do
59+
pp_name(remote_name)
60+
end
61+
5862
def pp_expr({:cons, _, _, _} = cons) do
5963
case cons_to_int_list(cons) do
6064
{:ok, l} ->
@@ -291,6 +295,9 @@ defmodule Gradient.ElixirExpr do
291295
{:throw, :not_found} ->
292296
# throw
293297
pp_expr(type) <> ", " <> pp_expr(var) <> " -> " <> pp_expr(body)
298+
299+
{_variable, :not_found} ->
300+
pp_expr(type) <> ", " <> pp_expr(var) <> " -> " <> pp_expr(body)
294301
end
295302
end
296303

@@ -482,6 +489,9 @@ defmodule Gradient.ElixirExpr do
482489
defp pp_cons({:cons, _, h, {:var, _, _} = v}), do: pp_expr(h) <> " | " <> pp_expr(v)
483490
defp pp_cons({:cons, _, h, t}), do: pp_expr(h) <> ", " <> pp_cons(t)
484491

492+
defp pp_name({:remote, _, {:var, _, _} = var, {:atom, _, n}}),
493+
do: pp_expr(var) <> "." <> to_string(n)
494+
485495
defp pp_name({:remote, _, {:atom, _, m}, {:atom, _, n}}),
486496
do: ElixirFmt.parse_module(m) <> to_string(n)
487497

1.99 KB
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmodule CallRemoteException do
2+
def call(conn, opts) do
3+
try do
4+
:ok
5+
rescue
6+
e in Plug.Conn.WrapperError ->
7+
exception = Exception.normalize(:error, e.reason, e.stack)
8+
_ = Sentry.capture_exception(exception, stacktrace: e.stack, event_source: :plug)
9+
Plug.Conn.WrapperError.reraise(e)
10+
11+
e ->
12+
_ = Sentry.capture_exception(e, stacktrace: __STACKTRACE__, event_source: :plug)
13+
:erlang.raise(:error, e, __STACKTRACE__)
14+
catch
15+
kind, reason ->
16+
message = "Uncaught #{kind} - #{inspect(reason)}"
17+
stack = __STACKTRACE__
18+
_ = Sentry.capture_message(message, stacktrace: stack, event_source: :plug)
19+
:erlang.raise(kind, reason, stack)
20+
end
21+
end
22+
end

test/gradient/elixir_fmt_test.exs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,52 @@ defmodule Gradient.ElixirFmtTest do
239239
end
240240
end
241241

242+
test "format call_intersect error" do
243+
error =
244+
{:type_error, :call_intersect, 7,
245+
[
246+
{:type, 0, :bounded_fun,
247+
[
248+
{:type, 0, :fun,
249+
[
250+
{:type, 0, :product,
251+
[
252+
{:atom, 0, :error},
253+
{:type, 0, :any, []},
254+
{:user_type, [file: 'Elixir.Exception.erl', location: 0], :stacktrace, []}
255+
]},
256+
{:user_type, [file: 'Elixir.Exception.erl', location: 0], :t, []}
257+
]},
258+
[]
259+
]},
260+
{:type, 0, :bounded_fun,
261+
[
262+
{:type, 0, :fun,
263+
[
264+
{:type, 0, :product,
265+
[
266+
{:user_type, [file: 'Elixir.Exception.erl', location: 0], :non_error_kind, []},
267+
{:var, 0, :payload},
268+
{:user_type, [file: 'Elixir.Exception.erl', location: 0], :stacktrace, []}
269+
]},
270+
{:var, 0, :payload}
271+
]},
272+
[]
273+
]}
274+
], {:remote, 7, {:atom, 7, Exception}, {:atom, 7, :normalize}}}
275+
276+
res = ElixirFmt.format_error(error, [])
277+
278+
expected = ~s"""
279+
The type of the function Exception.normalize, called on line 7 doesn't match the surrounding calling context.
280+
It has the following type
281+
\e[35m(:error, any(), stacktrace() -> t())\e[0m
282+
\e[35m(non_error_kind(), payload, stacktrace() -> payload)\e[0m\n
283+
"""
284+
285+
assert expected == :erlang.iolist_to_binary(res)
286+
end
287+
242288
@tag :skip
243289
test "format_expr_type_error/4" do
244290
opts = [forms: basic_erlang_forms()]

test/support/expr_data.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ defmodule Gradient.ExprData do
2828
{"char", {:char, 0, ?c}, "?c"},
2929
{"float", {:float, 0, 12.0}, "12.0"},
3030
{"integer", {:integer, 0, 1}, "1"},
31-
{"erlang string", {:string, 0, 'ala ma kota'}, ~s('ala ma kota')}
31+
{"erlang string", {:string, 0, 'ala ma kota'}, ~s('ala ma kota')},
32+
{"remote name", {:remote, 7, {:atom, 7, Exception}, {:atom, 7, :normalize}},
33+
"Exception.normalize"}
3234
]
3335
end
3436

0 commit comments

Comments
 (0)