Config section is empty and non-empty
Config section is empty and non-empty
I have this:
defmodule SomeModule do
@my_custom_config_section (Application.get_env(:my_app, :common)[:key1][:key2])
IO.puts("@my_custom_config_section debug1: #{Kernel.inspect(@my_custom_config_section)}")
IO.puts("@my_custom_config_section debug2: #{@my_custom_config_section}")
# ..........
And I have this when trying to run it - during compilation:
@my_custom_config_section (Application.get_env(:my_app, :common)[:key1][:key2])
# goood! the values are correct!
@my_custom_config_section debug1: %{aaa: "", bbb: "fdsafds", ccc: false, dddd: "afdsafdsfdsfds"}
# also good!
== Compilation error in file lib/my_app/some_module.ex ==
** (Protocol.UndefinedError) protocol String.Chars not implemented for %{aaa: "", bbb: "fdsafds", ccc: false, dddd: "afdsafdsfdsfds"}
However! This prints an empty string
defmodule SomeModule do
@my_custom_config_section (Application.get_env(:my_app, :common)[:key1][:key2])
#IO.puts("@my_custom_config_section debug1: #{Kernel.inspect(@my_custom_config_section)}")
#IO.puts("@my_custom_config_section debug2: #{@my_custom_config_section}")
# <--------- emtpy!
# @my_custom_config_section debug3:
IO.puts("@my_custom_config_section debug3: #{Kernel.inspect(@my_custom_config_section)}")
And this founds nothing in @my_custom_config_section:
def my_action(conn, params) do
a1 = @my_custom_config_section
# a1 is empty! Why???
end
At compile time, data exists. At runtime - not anymore.
:key3
IO.inspect(@my_custom_config_section, label: "@my_custom_config_section debug2")
Could you please remove all successful calls (we know that
Application.get_env/2 works.) Also, please specify exactly what you are doing, what you have received and what you had expected to receive.– mudasobwa
Jun 30 at 17:24
Application.get_env/2
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Are you sure you included
:key3in your configuration? It may help to see the entire final example code and it's output. Also, you can useIO.inspect(@my_custom_config_section, label: "@my_custom_config_section debug2"). This would avoid your needing to call inspect inside your puts.– Justin Wood
Jun 30 at 13:44