Distillery release throwing (FunctionClauseError) no function clause matching in System.get_env/2

I’m attempting to deploy a release using distillery. I am able to create the release on my server, but when I try to start the release on the server, I throw the following error:

$ _build/prod/rel/scandimension/bin/scandimension start
14:35:21.871 [info] Application scandimension exited: Scandimension.Application.start(:normal, []) returned an error: shutdown: failed to start child: ScandimensionWeb.Endpoint
    ** (EXIT) an exception was raised:
        ** (FunctionClauseError) no function clause matching in System.get_env/2
            (elixir) lib/system.ex:466: System.get_env(13974, nil)
            (phoenix) lib/phoenix/endpoint/supervisor.ex:357: Phoenix.Endpoint.Supervisor.port_to_integer/1
            (phoenix) lib/phoenix/endpoint/supervisor.ex:107: anonymous fn/6 in Phoenix.Endpoint.Supervisor.server_children/4
            (elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
            (phoenix) lib/phoenix/endpoint/supervisor.ex:99: Phoenix.Endpoint.Supervisor.server_children/4
            (phoenix) lib/phoenix/endpoint/supervisor.ex:59: Phoenix.Endpoint.Supervisor.init/1
            (stdlib) supervisor.erl:295: :supervisor.init/1
            (stdlib) gen_server.erl:374: :gen_server.init_it/2
{"Kernel pid terminated",application_controller,"{application_start_failure,scandimension,{{shutdown,{failed_to_start_child,'Elixir.ScandimensionWeb.Endpoint',{function_clause,[{'Elixir.System',get_env,[13974,nil],[{file,\"lib/system.ex\"},{line,466}]},{'Elixir.Phoenix.Endpoint.Supervisor',port_to_integer,1,[{file,\"lib/phoenix/endpoint/supervisor.ex\"},{line,357}]},{'Elixir.Phoenix.Endpoint.Supervisor','-server_children/4-fun-0-',6,[{file,\"lib/phoenix/endpoint/supervisor.ex\"},{line,107}]},{'Elixir.Enum','-reduce/3-lists^foldl/2-0-',3,[{file,\"lib/enum.ex\"},{line,1948}]},{'Elixir.Phoenix.Endpoint.Supervisor',server_children,4,[{file,\"lib/phoenix/endpoint/supervisor.ex\"},{line,99}]},{'Elixir.Phoenix.Endpoint.Supervisor',init,1,[{file,\"lib/phoenix/endpoint/supervisor.ex\"},{line,59}]},{supervisor,init,1,[{file,\"supervisor.erl\"},{line,295}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]}]}}},{'Elixir.Scandimension.Application',start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,scandimension,{{shutdown,{failed_to_start_child,'Elixir.ScandimensionWeb.Endpoint',{function_clause,[{'Elixir.System',get_env

Crash dump is being written to: erl_crash.dump...done

Based on the documentation for System.get_env, there is no such function for System.get_env/2, so I’m not sure what my next steps should be.

Any suggestions or guidance appreciated.

That’s a 1.9.0 function, but if it’s missing that means you aren’t running 1.9.0, but the only way it would have been compiled in was if it was compiled ‘with’ 1.9.0. Did you compile it with a 1.9.0 version of elixir but are deploying it on a system that only has 1.8.0 or older? You need to make sure both sides perfectly match.

It was compiled under version 1.9 (inadvertently) on the server, so both sides should have matched. I’m re-installing v1.8.1 and will recompile and see if that resolves the issue.

I’ve switched the server version back to Elixir 1.8.1, cleaned out and re-compiled the app. Now, after creating a release, I’m getting:

$ _build/prod/rel/scandimension/bin/scandimension foreground
15:40:25.872 [info] Application scandimension exited: Scandimension.Application.start(:normal, []) returned an error: shutdown: failed to start child: ScandimensionWeb.Endpoint
    ** (EXIT) an exception was raised:
        ** (FunctionClauseError) no function clause matching in System.get_env/1
            (elixir) lib/system.ex:390: System.get_env(13974)
            (phoenix) lib/phoenix/endpoint/supervisor.ex:357: Phoenix.Endpoint.Supervisor.port_to_integer/1
            (phoenix) lib/phoenix/endpoint/supervisor.ex:107: anonymous fn/6 in Phoenix.Endpoint.Supervisor.server_children/4
            (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3
            (phoenix) lib/phoenix/endpoint/supervisor.ex:99: Phoenix.Endpoint.Supervisor.server_children/4
            (phoenix) lib/phoenix/endpoint/supervisor.ex:59: Phoenix.Endpoint.Supervisor.init/1
            (stdlib) supervisor.erl:295: :supervisor.init/1
            (stdlib) gen_server.erl:374: :gen_server.init_it/2
{"Kernel pid terminated",application_controller,"{application_start_failure,scandimension,{{shutdown,{failed_to_start_child,'Elixir.ScandimensionWeb.Endpoint',{function_clause,[{'Elixir.System',get_env,[13974],[{file,\"lib/system.ex\"},{line,390}]},{'Elixir.Phoenix.Endpoint.Supervisor',port_to_integer,1,[{file,\"lib/phoenix/endpoint/supervisor.ex\"},{line,357}]},{'Elixir.Phoenix.Endpoint.Supervisor','-server_children/4-fun-0-',6,[{file,\"lib/phoenix/endpoint/supervisor.ex\"},{line,107}]},{'Elixir.Enum','-reduce/3-lists^foldl/2-0-',3,[{file,\"lib/enum.ex\"},{line,1940}]},{'Elixir.Phoenix.Endpoint.Supervisor',server_children,4,[{file,\"lib/phoenix/endpoint/supervisor.ex\"},{line,99}]},{'Elixir.Phoenix.Endpoint.Supervisor',init,1,[{file,\"lib/phoenix/endpoint/supervisor.ex\"},{line,59}]},{supervisor,init,1,[{file,\"supervisor.erl\"},{line,295}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]}]}}},{'Elixir.Scandimension.Application',start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,scandimension,{{shutdown,{failed_to_start_child,'Elixir.ScandimensionWeb.Endpoint',{function_clause,[{'Elixir.System',get_env

If I try the failing command in iex, I get:

iex(2)> System.get_env(13974)
** (FunctionClauseError) no function clause matching in System.get_env/1    
    
    The following arguments were given to System.get_env/1:
    
        # 1
        13974
    
    Attempted function clauses (showing 1 out of 1):
    
        def get_env(varname) when is_binary(varname)
    
    (elixir) lib/system.ex:390: System.get_env/1

Yep! That is a totally legit error now. Somehow the integer 13974 is being looked up in the OS system environment, but the system environment is only string->string mappings, thus of course System.get_env(13974) would fail. :slight_smile:

I’d guess that the port mapping passed to the endpoint (either explicitly or via a config) is using the system environment but is passing an integer as the environment ‘key’ to look up instead or it is passed as a default value instead of a string. Can you search for 13974 globally and give the requisite expressions that it appears in?

I had a typo in my config/prod.exs. I corrected it to be:

config :scandimension, ScandimensionWeb.Endpoint,
  http: [:inet6, port: System.get_env("PORT")|| 13974],
  url: [host: "localhost", port: 13974],

and it now works as expected. Thanks for the assistance.

1 Like

Woot! Happens to us all. :slight_smile: