Extended error information (EEP-54) and NIFs

Lukas Larsson lukas@REDACTED
Fri Jun 11 14:30:07 CEST 2021


On Fri, Jun 11, 2021 at 12:30 PM Roger Lipscombe <roger@REDACTED>

> 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, #{}}])

format_error(_Reason, [{?MODULE, my_wrapper, 1, _}|_]) ->
  #{ 1 => "invalid password" }.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210611/e9c9761d/attachment.htm>

More information about the erlang-questions mailing list