-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Unify formatting of some common expansion errors #5797
Unify formatting of some common expansion errors #5797
Conversation
These errors can now be formatted via either elixir_expand:format_error/1 or elixir_clauses:format_error/1.
lib/elixir/src/elixir_clauses.erl
Outdated
format_error(missing_do_or_after_in_receive) -> | ||
"missing do or after keyword in receive"; | ||
"missing :do or :after in \"receive\""; | ||
|
||
format_error(missing_keyword_in_try) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keyword
–> option
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. Was thinking, what if we unify this error as well and have something like
format_error({missing_options, Kind, Opts}) ->
StringOpts = 'Elixir.Enum':map_join(Opts, <<"/">>, fun 'Elixir.Macro':to_string/1),
io_lib:format("missing ~ts in \"~ts\"", [StringOpts, Kind]);
Wdyt? We would unify try
and receive
as well this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe Elixir.Enum
won't be available on that step, we could use Erlang alternative.
I think it makes sense to unify like that. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also perhaps generalize missing_do
to missing_option
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lexmag definitely, that's what I meant. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful. 💛
These errors can now be formatted via either
elixir_expand:format_error/1
orelixir_clauses:format_error/1
.