From 29a6a4e48c952707f5869cf36f104710050da768 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Sat, 15 Mar 2025 08:40:03 +0900 Subject: [PATCH 1/2] Fix handling of ErlangError when :general key is chardata Close https://github.com/elixir-lang/elixir/issues/14322 https://github.com/erlang/otp/blob/57cee857031cc08a47c7d2f4f21a6fac87781f91/lib/public_key/src/pubkey_os_cacerts.erl#L300 --- lib/elixir/lib/exception.ex | 2 +- lib/elixir/test/elixir/exception_test.exs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/elixir/lib/exception.ex b/lib/elixir/lib/exception.ex index fab8051949b..8aeb2f52c77 100644 --- a/lib/elixir/lib/exception.ex +++ b/lib/elixir/lib/exception.ex @@ -2718,7 +2718,7 @@ defmodule ErlangError do {:ok, reason, IO.iodata_to_binary([":\n\n" | Enum.map(args_errors, &arg_error/1)])} general = extra[:general] -> - {:ok, reason, ": " <> general} + {:ok, reason, ": " <> IO.chardata_to_string(general)} true -> :error diff --git a/lib/elixir/test/elixir/exception_test.exs b/lib/elixir/test/elixir/exception_test.exs index ef9cb322e23..54cfd76c73b 100644 --- a/lib/elixir/test/elixir/exception_test.exs +++ b/lib/elixir/test/elixir/exception_test.exs @@ -50,6 +50,19 @@ defmodule ExceptionTest do {:io, :put_chars, [self(), <<222>>], [error_info: %{module: __MODULE__, function: :dummy_error_extras}]} ]) + + assert %ErlangError{ + original: {:failed_load_cacerts, :enoent}, + reason: ": Failed to load cacerts: operating system CA bundle could not be located" + } = + Exception.normalize(:error, {:failed_load_cacerts, :enoent}, [ + {:pubkey_os_cacerts, :get, 0, + [ + file: ~c"pubkey_os_cacerts.erl", + line: 53, + error_info: %{cause: :enoent, module: :pubkey_os_cacerts} + ]} + ]) end test "format/2 without stacktrace" do From 39ea53e6454dc494cf90efc5ca643fb1b3c53937 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Sat, 15 Mar 2025 19:05:32 +0900 Subject: [PATCH 2/2] Use dummy error module --- lib/elixir/test/elixir/exception_test.exs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/elixir/test/elixir/exception_test.exs b/lib/elixir/test/elixir/exception_test.exs index 54cfd76c73b..36d6377f0c1 100644 --- a/lib/elixir/test/elixir/exception_test.exs +++ b/lib/elixir/test/elixir/exception_test.exs @@ -51,17 +51,10 @@ defmodule ExceptionTest do [error_info: %{module: __MODULE__, function: :dummy_error_extras}]} ]) - assert %ErlangError{ - original: {:failed_load_cacerts, :enoent}, - reason: ": Failed to load cacerts: operating system CA bundle could not be located" - } = + assert %ErlangError{original: {:failed_load_cacerts, :enoent}, reason: ": this is chardata"} = Exception.normalize(:error, {:failed_load_cacerts, :enoent}, [ {:pubkey_os_cacerts, :get, 0, - [ - file: ~c"pubkey_os_cacerts.erl", - line: 53, - error_info: %{cause: :enoent, module: :pubkey_os_cacerts} - ]} + [error_info: %{module: __MODULE__, function: :dummy_error_chardata}]} ]) end @@ -1079,4 +1072,8 @@ defmodule ExceptionTest do end def dummy_error_extras(_exception, _stacktrace), do: %{general: "foo"} + + def dummy_error_chardata(_exception, _stacktrace) do + %{general: ~c"this is " ++ [~c"chardata"], reason: ~c"this " ++ [~c"too"]} + end end