revati

revati

Not an already existing atom` error fixed by arbitrary change in module. needs to be done after every `mix phx.server

I assume its a beam issue i have. I don’t know honestly.

Setup

  • my project contains fallowing module:
defmodule MyApp.Access do
  def permissions() do
    %{
      permission_x: [:list, :show],
      ...
    }
  end
end

In total project has 7 places where this atom permission_x is hardcoded.

Steps to consistently reproduce issue.

  1. open new terminal tab.
  2. ~ mix phx.server → server starts
  3. in browser i request 127.0.0.1:4000 → i get error. This error seems odd, as i have module where required atom is hardcoded, so how can it be not an already existing atom, but ok?
[error] #PID<0.766.0> running MayAppWeb.Endpoint (connection #PID<0.765.0>, stream id 1) terminated
Server: 127.0.0.1:4000 (http)
Request: GET /
** (exit) an exception was raised:
    ** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an already existing atom

        :erlang.binary_to_existing_atom("permission_x", :utf8)
  1. I make arbitrary change to MyApp.Access module: (can’t add empty line, as on-save it is removed by formatter, so just added :ok)
defmodule MyApp.Access do
+ :ok
  def permissions() do
  1. in browser i request 127.0.0.1:4000 → and it works → terminal output:
Compiling 4 files (.ex)
[info] GET /
[info] Sent 200 in 262ms
  1. I can remove :ok line and it keeps working. → I assume compilation part is the secret sauce that fixes issue.

If i stop server ctrl+c and start again (step 2). im back in step 3. it does not work again. and i need to do some arbitrary changes to MyApp.Access to force compilation.

Is there a way to see what files are compiled there? Maybe there is some secret.
Also why it after restart loads old/stale binary of MyApp.Access not the latest one that worked?

I have spent a lot time to debug this and i dont understand what could even be next steps to try to fix this. :tired_face:

Marked As Solved

LostKobrakai

LostKobrakai

The beam can start in one of two modes (configured through build_embedded iirc). Either it preloads all modules at the start, or it does load modules only on demand, when e.g. some code tries to call a function on it. By default in dev the beam runs in the second mode for the improved speed in startup. I’d expect that to be the reason for what you’re seeing

Also Liked

hst337

hst337

I’ve though so too, but I can see that

mix new sample
cd sample
iex -S mix

iex> String.to_existing_atom "world"

Works fine

hmm

Last Post!

hst337

hst337

You can try start iex -S mix again, and you’ll see that the module is not loaded

Where Next?

Popular in Questions Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement