Extending EEP54 with custom pretty printing

I am incorporating Implement extended error information for binary construction by bjorng · Pull Request #5281 · erlang/otp · GitHub, which brings excellent error messages during binary construction, within Elixir.

One limitation is that the format_error/2 callback is using Erlang pretty printing for values, which may not print the terms as expected in Elixir. It would be nice if we could re-use the same message formatting with a custom pretty printer. However, I am not sure how we can customize this.

One option would be to call format_error/3 with additional options, but that can unreasonably extend the surface area of EEP 54. Another option is for me to augment the error_info map in the stacktrace with a pretty_printer field, rebuild the head of the stacktrace, and give it to format_error/2, which Erlang/OTP would look up and use.

Does anyone have other suggestions? I will be glad to send PRs to both EEP 54 and Erlang/OTP once a path is confirmed.

Thank you!

5 Likes

Yes, I think that is a simple and clean way to do it. Unless some suggests something even better, go for it!

3 Likes

To close the loop for anyone who were watching this thread, PR sent here: Add options to binary construction error_info formatting by josevalim · Pull Request #5752 · erlang/otp · GitHub

It includes an additional option so we can improve errors from erl_eval too!

5 Likes