diff options
author | Björn Gustavsson <bjorn@erlang.org> | 2022-02-08 06:38:30 +0100 |
---|---|---|
committer | Björn Gustavsson <bjorn@erlang.org> | 2022-02-09 14:03:19 +0100 |
commit | 1ee6eda07d299b3796b6043cc8359aa8bd9d7c31 (patch) | |
tree | 1e8ea07ab411fdf8847feac120bc80051bb85fb3 /erts/emulator/beam/atom.names | |
parent | 2e612c1b4e9c551a6dd80743205f586ad38ed9e1 (diff) | |
download | erlang-1ee6eda07d299b3796b6043cc8359aa8bd9d7c31.tar.gz |
Provide more information for failed record operations
When a record operation fails, a `{badrecord,Tag}` error exception
is raised, where `Tag` is the name of the record. For example, if
we have this function:
-record(foo, {a,b,c,d}).
bar(R) ->
R#foo.a.
we will get the following exception if we call `bar/1` with something
else than a #foo{} record:
1> t:bar({x,y,z}).
** exception error: {badrecord,foo}
in function t:bar/1 (t.erl, line 7)
When records were first introduced, there were no line numbers in
exceptions, so if a record operation failed in a large function
knowing the record name could be useful.
Nowadays, the line number usually makes it obvious which kind of
record the failed operation expected. It would be more useful to
know the actual value passed to the record operation.
This commit changes the exception for a failed record operation to
`{badrecord,ActualValue}`. For example:
1> t:bar({x,y,z}).
** exception error: {badrecord,{x,y,z}}
in function t:bar/1 (t.erl, line 7)
2> t:bar(lists:seq(1, 1000)).
** exception error: {badrecord,[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27|...]}
in function t:bar/1 (t.erl, line 7)
Note that it is not documented what the exception for a failed record
operation is supposed to look like. Furthermore, it is unlikely that
there is exisiting code that catches expressions involving records
operations and tries to match the exact error reason. Therefore, we
don't consider this an incompatible change.
Diffstat (limited to 'erts/emulator/beam/atom.names')
-rw-r--r-- | erts/emulator/beam/atom.names | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/erts/emulator/beam/atom.names b/erts/emulator/beam/atom.names index 313c60d342..206bb5e278 100644 --- a/erts/emulator/beam/atom.names +++ b/erts/emulator/beam/atom.names @@ -118,7 +118,8 @@ atom await_sched_wall_time_modifications atom awaiting_load atom awaiting_unload atom backtrace backtrace_depth -atom badarg badarith badarity badfile badfun badkey badmap badmatch badsig +atom badarg badarith badarity badfile badfun badkey badmap badmatch +atom badrecord badsig atom badopt badtype atom bad_map_iterator atom bag |