diff --git a/lib/bandit/pipeline.ex b/lib/bandit/pipeline.ex index 8d772595..1365c955 100644 --- a/lib/bandit/pipeline.ex +++ b/lib/bandit/pipeline.ex @@ -209,7 +209,15 @@ defmodule Bandit.Pipeline do ) :: {:ok, Bandit.HTTPTransport.t()} | {:error, term()} defp handle_error(:error, %Plug.Conn.WrapperError{} = error, _, transport, span, opts, metadata) do # Unwrap the inner error and handle it - handle_error(error.kind, error.reason, error.stack, transport, span, opts, metadata) + handle_error( + error.kind, + Exception.normalize(:error, error.reason, error.stack), + error.stack, + transport, + span, + opts, + metadata + ) end defp handle_error(:error, %type{} = error, stacktrace, transport, span, opts, metadata) diff --git a/test/bandit/http1/plug_test.exs b/test/bandit/http1/plug_test.exs index d2973ca5..538dd925 100644 --- a/test/bandit/http1/plug_test.exs +++ b/test/bandit/http1/plug_test.exs @@ -112,7 +112,7 @@ defmodule HTTP1PlugTest do get "/" do # Quiet the compiler _ = conn - raise "boom" + 1 = 0 end end @@ -134,9 +134,15 @@ defmodule HTTP1PlugTest do SimpleHTTP1Client.send(client, "GET", "/hello_world", ["host: banana"]) assert SimpleHTTP1Client.connection_closed_for_reading?(client) - assert_receive {:log, %{level: :error, msg: {:string, msg}}}, 500 + assert_receive {:log, %{level: :error, msg: {:string, msg}, meta: meta}}, 500 refute msg =~ "(Plug.Conn.WrapperError)" - assert msg =~ "** (RuntimeError) boom" + assert msg =~ "** (MatchError)" + + assert %{ + domain: [:elixir, :bandit], + crash_reason: {%MatchError{}, [_ | _] = _stacktrace}, + conn: %Plug.Conn{} + } = meta end end