aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/error.h
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-03-31 08:47:57 +0200
committerBjörn Gustavsson <[email protected]>2015-04-15 15:12:33 +0200
commit5bb8262bd4ae8dbcc7438e80de5cedac7ccee1af (patch)
tree5e238aa9ab7e7dad021a56cb7ac9d0c07a54b46e /erts/emulator/beam/error.h
parent44c5a955c8409cc98a5fbdec7898de46b9e5dfbe (diff)
downloadotp-5bb8262bd4ae8dbcc7438e80de5cedac7ccee1af.tar.gz
otp-5bb8262bd4ae8dbcc7438e80de5cedac7ccee1af.tar.bz2
otp-5bb8262bd4ae8dbcc7438e80de5cedac7ccee1af.zip
Raise more descriptive error messages for failed map operations
According to EEP-43 for maps, a 'badmap' exception should be generated when an attempt is made to update non-map term such as: <<>>#{a=>42} That was not implemented in the OTP 17. José Valim suggested that we should take the opportunity to improve the errors coming from map operations: http://erlang.org/pipermail/erlang-questions/2015-February/083588.html This commit implement better errors from map operations similar to his suggestion. When a map update operation (Map#{...}) or a BIF that expects a map is given a non-map term, the exception will be: {badmap,Term} This kind of exception is similar to the {badfun,Term} exception from operations that expect a fun. When a map operation requires a key that is not present in a map, the following exception will be raised: {badkey,Key} José Valim suggested that the exception should be {badkey,Key,Map}. We decided not to do that because the map could potentially be huge and cause problems if the error propagated through links to other processes. For BIFs, it could be argued that the exceptions could be simply 'badmap' and 'badkey', because the bad map and bad key can be found in the argument list for the BIF in the stack backtrace. However, for the map update operation (Map#{...}), the bad map or bad key will not be included in the stack backtrace, so that information must be included in the exception reason itself. For consistency, the BIFs should raise the same exceptions as update operation. If more than one key is missing, it is undefined which of keys that will be reported in the {badkey,Key} exception.
Diffstat (limited to 'erts/emulator/beam/error.h')
-rw-r--r--erts/emulator/beam/error.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/erts/emulator/beam/error.h b/erts/emulator/beam/error.h
index ddc2c1396d..e63967adb6 100644
--- a/erts/emulator/beam/error.h
+++ b/erts/emulator/beam/error.h
@@ -140,7 +140,13 @@
#define EXC_NOTSUP ((17 << 8) | EXC_ERROR)
/* Not supported */
-#define NUMBER_EXIT_CODES 18 /* The number of exit code indices */
+#define EXC_BADMAP ((18 << 8) | EXC_ERROR)
+ /* Bad map */
+
+#define EXC_BADKEY ((19 << 8) | EXC_ERROR)
+ /* Bad key in map */
+
+#define NUMBER_EXIT_CODES 20 /* The number of exit code indices */
/*
* Internal pseudo-error codes.
@@ -152,6 +158,8 @@
*/
#define BADARG EXC_BADARG
#define BADARITH EXC_BADARITH
+#define BADKEY EXC_BADKEY
+#define BADMAP EXC_BADMAP
#define BADMATCH EXC_BADMATCH
#define SYSTEM_LIMIT EXC_SYSTEM_LIMIT