Skip to content

Fix exunit format_message crash when message is not a string #14695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lukaszsamson
Copy link
Contributor

I noticed this crash in the logs. I'm not sure if a struct is supposed to be in message. The ExUnit.AssertionError struct typespec has type any

an exception was raised:
    ** (FunctionClauseError) no function clause matching in ExUnit.Formatter.pad_multiline_2
USER_PATH_ex_unit_formatter.ex:735: ExUnit.Formatter.pad_multiline(#Ecto.Changeset<action: nil, changes: %{foo_id: 123}, errors: [prefered_locale: {"can't be blank", [validation: :required]}], data: #Foo.Domain<>, valid?: false, ...>, 5)
USER_PATH_ex_unit_formatter.ex:616: ExUnit.Formatter.format_message_2
USER_PATH_ex_unit_formatter.ex:377: ExUnit.Formatter.format_exception_6
USER_PATH_ex_unit_formatter.ex:278: anonymous fn_7 in ExUnit.Formatter.format_test_failure_5
        (elixir 1.18.2) <REDACTED: user-file-path>:1815: anonymous fn_2 in Enum.map_join_3
        (elixir 1.18.2) <REDACTED: user-file-path>:4493: Enum.map_intersperse_list_3
        (elixir 1.18.2) <REDACTED: user-file-path>:1815: Enum.map_join_3
USER_PATH_ex_unit_formatter.ex:277: ExUnit.Formatter.format_test_failure_5

@josevalim
Copy link
Member

Please rebase or change of branches! Thanks!

@lukaszsamson lukaszsamson force-pushed the ls-fix-exunit-format-error branch from adac9ca to d98a77e Compare August 5, 2025 10:22
@josevalim
Copy link
Member

Thank you, can we have a test? We already have a suite that verifies how failures and, although a message is always meant to be a string, I agree calling inspect as fallback is good. Here is a good candidate for a unit test: https://github.com/elixir-lang/elixir/blob/main/lib/ex_unit/test/ex_unit/formatter_test.exs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants