Re: Extended error information (EEP-54) and NIFs
Lukas Larsson <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAP3zBqO6V3FFFoo5Oag6gBGBv6-Etcr8-C+Y3LHNcYVd7M49rQ@mail.gmail.com> |
Hello, On Fri, Jun 11, 2021 at 12:30 PM Roger Lipscombe <[email protected]> wrote: > The extended error information in EEP-54 is amazing, but I only see > mention of BIFs in the notes. Can it be applied to NIFs as well? If > so, are there any examples/documentation? > There are no NIF primitives yet to raise that type of exception, but we have been talking about adding them. The best you can do now is to throw an error and catch it in a NIF wrapper and then rethrow it again with the extra error_info. Something like: my_wrapper(Arg1) -> try my_nif(Arg1) catch error:badarg -> error(badarg, [Arg1], [{error_info, #{}}]) end. format_error(_Reason, [{?MODULE, my_wrapper, 1, _}|_]) -> #{ 1 => "invalid password" }. Lukas