[erlang-questions] Improve errors for maps

José Valim jose.valim@REDACTED
Fri Feb 27 15:17:07 CET 2015

Since maps are still marked are experimental, I would love if we take the
opportunity to improve the errors coming from map operations.

For example, a bad update just fails with badarg, without giving further
hints of what went wrong:

1> (foo)#{foo := 1}.
** exception error: bad argument: foo

Or when the key does not exist:

1> (#{})#{foo := 1}.
** exception error: bad argument
     in function  maps:update/3

Although the shell helps a bit with formatting it, it is hard to decipher
in logs and we frequently have reports of the error message not being clear
to developers.

I would love if we could, at least for the syntax based operations,
introduce two errors:

1. {badmap, Term} - raised when a map was expected but got something else
(this would replace the first error and it is an improvement over the error
records used to raise)

2. {badkey, Key, Map} - raised when we expected a Map to have Key but it
does not. Useful for the := syntax and it could also be used if we ever add
an access operation to maps

If we segregate the errors as proposed, we will have plenty of opportunity
to improve the reports in shell and in error loggers.


*José Valim*
Skype: jv.ptec
Founder and Lead Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150227/574280d9/attachment.htm>

More information about the erlang-questions mailing list