With Elixir 1.7.2/OTP21 Mix.env() no longer produces nil in production (i.e. inside release). Instead crashes because GenServer Mix.State isn’t running. I found a workaround in checking if Mix.State is running (Process.whereis(Mix.State) != nil) but surely Mix.env() should return nil, right?
** (EXIT) exited in: GenServer.call(Mix.State, {:get, {Map, :get, [:env, :dev]}}, 5000)
** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
Well, I have a few if Mix.env() == :test do things scenarios which would be ignored if Mix.env() returned nil. Now I have to wrap them in a if Process.whereis(Mix.State) != nil.
Yeah I’m pretty confused about how this wasn’t blowing up already, I normally get a Module Mix is unavailable error. The general solution here is to not call Mix.env in runtime code. You can either do so at build time OR you use if Application.get_env(:my_app, :something_meaningful) instead, and then set that flag in your config.exs