better error message when using term_to_binary with [safe] ?

Pablo Platt <>
Sun Mar 13 20:13:29 CET 2011


When using binary_to_term with the [safe] option, with a non existing atom it 
just throws an error
but doesn't tell you what's wrong.
Is it possible that the error message will tell me what atom was missing?

1> binary_to_term(<<131,100,0,6,109,121,97,116,111,109>>, [safe]).
** exception error: bad argument
     in function  binary_to_term/2
        called as binary_to_term(<<131,100,0,6,109,121,97,116,111,109>>,[safe])

What is the best way to tell erlang what are the 'safe' atoms in my program?
I'm currently defining and calling a trusted_atoms/0 function that just returns 
a list of all atoms I need.
Is there a 'cleaner' way to do that?

init() ->
    A = trusted_atoms().

trusted_atoms() ->
    [atom1, atom2 atom3].


More information about the erlang-questions mailing list