简体   繁体   中英

Production Elixir Not Finding Existing Atoms

I'm using a library that parses input into maps using already-existing keys (Poison). For whatever reason, in production, it thinks the keys don't exist, and I can't figure out why. I do have a few pieces of information that I'm hoping someone who isn't a rookie is willing to help me figure out what's going on:

1:

If I do an IEX session (iex -S mix), I can run :erlang.binary_to_existing_atom("first_name", :"utf8") without trouble. But in production, instead I get

** (ArgumentError) argument error
  :erlang.binary_to_existing_atom("first_name", :utf8)

2:

I can run :first_name immediately before :erlang.binary_to_existing_atom on production, and it works fine, since by then, the atom has been created. BUT , I can't run :first_name followed by the library's method: Poison.Parser.parse!(~s(#{body}), keys: :atoms!) as it throws the error, which I find to be strange.

3:

I'm using Heroku, not sure if that matters. The atoms are defined within an Ecto model, also not sure if that matters. Any help would be greatly appreciated - thanks in advance!

You'll note that the Erlang documentation says:

binary_to_existing_atom(Binary, Encoding) -> atom()

Types:

Binary = binary() Encoding = latin1 | unicode | utf8 Works like binary_to_atom/2, but the atom must already exist.

Failure: badarg if the atom does not already exist.

If I were you I'd try to figure out why the :first_name atom isn't there before the call is run.

Erlang compiler optimizes away known pure function calls and replaces them with the call result. This omits the original atom from the module, thus making it non-existent. The bug is here https://bugs.erlang.org/browse/ERL-453 and I might be fixing it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM