erlang / eep

Erlang Enhancement Proposals
http://www.erlang.org/erlang-enhancement-proposals/
264 stars 67 forks source link

EEP 54: Extended error information for BIFs #14

Closed bjorng closed 4 years ago

bjorng commented 4 years ago

I have changed the return value of format_error/3 to be a map. That way, in the future it would be easier to provide more information about errors in a backwards-compatible way. (Suggested by José Valim.)

bjorng commented 4 years ago

I have now updated the reference implementation to provide extended error information for most C-implemented BIFs in the erlang module. (It remains to provide extended error information for Erlang-implemented BIFs in the erlang module.)

I found one BIF that will raise a badarg exception even if the arguments are good, namely monitor_node/2:

1> monitor_node(node@host, true).
** exception error: bad argument
     in function  monitor_node/2
        called as monitor_node(node@host,true)

If distribution is not started (the current node is not alive), monitor_node/2 always raises a badarg exception. With the suggested way of always associating a message to a specific argument, there is no way to provide extended error information.

Should we change monitor_node/2 to raise another exception if the current node is not alive, for example not_alive?

Or should we extend the EEP to allow the reporting of a message not associated with any of the arguments?

Or maybe allow format_error/3 to change the badarg to something else? That is, make it possible to produce the following message:

1> monitor_node(node@host, true).
** exception error: the current node is not alive
     in function  monitor_node/2
        called as monitor_node(node@host,true)