Fix Mix.env() runtime crash in releases
Capture Mix.env() at compile time via module attribute since Mix is not available at runtime in production releases.
This commit is contained in:
parent
8b51b02d45
commit
719ac1eb0f
1 changed files with 4 additions and 2 deletions
|
|
@ -441,6 +441,9 @@ defmodule SnmpKit.SnmpLib.Config do
|
|||
|
||||
## Private Implementation
|
||||
|
||||
# Capture Mix.env() at compile time since Mix is not available in releases
|
||||
@compile_env if Code.ensure_loaded?(Mix), do: Mix.env(), else: :prod
|
||||
|
||||
# Environment detection with multiple fallbacks
|
||||
defp detect_environment(opts) do
|
||||
cond do
|
||||
|
|
@ -448,8 +451,7 @@ defmodule SnmpKit.SnmpLib.Config do
|
|||
env = System.get_env("MIX_ENV") -> String.to_atom(env)
|
||||
env = System.get_env("SNMP_LIB_ENV") -> String.to_atom(env)
|
||||
env = Application.get_env(:snmp_lib, :environment) -> env
|
||||
Code.ensure_loaded?(Mix) -> Mix.env()
|
||||
true -> :dev
|
||||
true -> @compile_env
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue