Skip to content

Commit 5998c0e

Browse files
authored
Fix handling of ErlangError when :general key is chardata (#14329)
1 parent 3e89296 commit 5998c0e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/elixir/lib/exception.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,7 @@ defmodule ErlangError do
27182718
{:ok, reason, IO.iodata_to_binary([":\n\n" | Enum.map(args_errors, &arg_error/1)])}
27192719

27202720
general = extra[:general] ->
2721-
{:ok, reason, ": " <> general}
2721+
{:ok, reason, ": " <> IO.chardata_to_string(general)}
27222722

27232723
true ->
27242724
:error

lib/elixir/test/elixir/exception_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ defmodule ExceptionTest do
5050
{:io, :put_chars, [self(), <<222>>],
5151
[error_info: %{module: __MODULE__, function: :dummy_error_extras}]}
5252
])
53+
54+
assert %ErlangError{original: {:failed_load_cacerts, :enoent}, reason: ": this is chardata"} =
55+
Exception.normalize(:error, {:failed_load_cacerts, :enoent}, [
56+
{:pubkey_os_cacerts, :get, 0,
57+
[error_info: %{module: __MODULE__, function: :dummy_error_chardata}]}
58+
])
5359
end
5460

5561
test "format/2 without stacktrace" do
@@ -1066,4 +1072,8 @@ defmodule ExceptionTest do
10661072
end
10671073

10681074
def dummy_error_extras(_exception, _stacktrace), do: %{general: "foo"}
1075+
1076+
def dummy_error_chardata(_exception, _stacktrace) do
1077+
%{general: ~c"this is " ++ [~c"chardata"], reason: ~c"this " ++ [~c"too"]}
1078+
end
10691079
end

0 commit comments

Comments
 (0)