Extended error information (EEP-54) and NIFs

20 views
Skip to first unread message

Roger Lipscombe

unread,
Jun 11, 2021, 6:30:06 AM6/11/21
to erlang-questions
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?

Lukas Larsson

unread,
Jun 11, 2021, 8:30:37 AM6/11/21
to Roger Lipscombe, erlang-questions
Hello,

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

Roger Lipscombe

unread,
Jun 11, 2021, 9:18:02 AM6/11/21
to Lukas Larsson, erlang-questions
On Fri, 11 Jun 2021 at 13:30, Lukas Larsson <lu...@erlang.org> wrote:
> 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.

Thanks. That's useful to know. The actual use-case, however, was "why
is evp_generate_key_nif returning badarg?". You'll note that that's
not one of *my* NIFs :-)

So that got me thinking about why the crypto NIFs haven't been
extended with EEP-54 yet. "no NIF primitives yet" answers my question,
thanks.
Reply all
Reply to author
Forward
0 new messages