title: Erlang application undef error (exited: {bad_return,)
body: <p>I am trying to run a custom application but get multiple errors. I believe the main egs app gets an error because it calls the egs patch app which has an undefined type. I cant figure out how to get this working I have tried recompiling the code many times in regards to others with a similar problem but nothing seems to work. The cowboy start listener remains undefined.</p>
  
  <p>This is the error I receive.</p>
  
  <pre><code>    =CRASH REPORT==== 10-Apr-2013::21:02:00 ===
    crasher:
      initial call: application_master:init/4
      pid: &lt;0.106.0&gt;
      registered_name: []
      exception exit: {bad_return,
                          {{egs_patch_app,start,[normal,[]]},
                           {'EXIT',
                               {undef,
                                   [{cowboy,start_listener,
                                        [{patch,11030},
                                         10,cowboy_tcp_transport,
                                         [{port,11030}],
                                         egs_patch_protocol,[]],
                                        []},
                                    {egs_patch_app,start_listeners,1,
                                        [{file,"src/egs_patch_app.erl"},
                                         {line,44}]},
                                    {egs_patch_app,start,2,
                                        [{file,"src/egs_patch_app.erl"},
                                         {line,31}]},
                                    {application_master,start_it_old,4,
                                        [{file,"application_master.erl"},
                                         {line,274}]}]}}}}
        in function  application_master:init/4 (application_master.erl, line 138)
      ancestors: [&lt;0.105.0&gt;]
      messages: [{'EXIT',&lt;0.107.0&gt;,normal}]
      links: [&lt;0.105.0&gt;,&lt;0.7.0&gt;]
      dictionary: []
      trap_exit: true
      status: running
      heap_size: 610
      stack_size: 27
      reductions: 124
    neighbours:
  
  =INFO REPORT==== 10-Apr-2013::21:02:00 ===
      application: egs_patch
      exited: {bad_return,
                  {{egs_patch_app,start,[normal,[]]},
                   {'EXIT',
                       {undef,
                           [{cowboy,start_listener,
                                [{patch,11030},
                                 10,cowboy_tcp_transport,
                                 [{port,11030}],
                                 egs_patch_protocol,[]],
                                []},
                            {egs_patch_app,start_listeners,1,
                                [{file,"src/egs_patch_app.erl"},{line,44}]},
                            {egs_patch_app,start,2,
                                [{file,"src/egs_patch_app.erl"},{line,31}]},
                            {application_master,start_it_old,4,
                                [{file,"application_master.erl"},
                                 {line,274}]}]}}}}
      type: temporary
  
  =CRASH REPORT==== 10-Apr-2013::21:02:00 ===
    crasher:
      initial call: application_master:init/4
      pid: &lt;0.75.0&gt;
      registered_name: []
      exception exit: {bad_return,
                          {{egs_app,start,[normal,[]]},
                           {'EXIT',
                               {undef,
                                   [{cowboy,start_listener,
                                        [{login,12030},
                                         10,cowboy_ssl_transport,
                                         [{port,12030},
                                          {certfile,"priv/ssl/servercert.pem"},
                                          {keyfile,"priv/ssl/serverkey.pem"},
                                          {password,"alpha"}],
                                         egs_login_protocol,[]],
                                        []},
                                    {egs_app,start_login_listeners,1,
                                        [{file,"src/egs_app.erl"},{line,55}]},
                                    {egs_app,start,2,
                                        [{file,"src/egs_app.erl"},{line,38}]},
                                    {application_master,start_it_old,4,
                                        [{file,"application_master.erl"},
                                         {line,274}]}]}}}}
        in function  application_master:init/4 (application_master.erl, line 138)
      ancestors: [&lt;0.74.0&gt;]
      messages: [{'EXIT',&lt;0.76.0&gt;,normal}]
      links: [&lt;0.74.0&gt;,&lt;0.7.0&gt;]
      dictionary: []
      trap_exit: true
      status: running
      heap_size: 987
      stack_size: 27
      reductions: 185
    neighbours:
  
  =INFO REPORT==== 10-Apr-2013::21:02:00 ===
      application: egs
      exited: {bad_return,
                  {{egs_app,start,[normal,[]]},
                   {'EXIT',
                       {undef,
                           [{cowboy,start_listener,
                                [{login,12030},
                                 10,cowboy_ssl_transport,
                                 [{port,12030},
                                  {certfile,"priv/ssl/servercert.pem"},
                                  {keyfile,"priv/ssl/serverkey.pem"},
                                  {password,"alpha"}],
                                 egs_login_protocol,[]],
                                []},
                            {egs_app,start_login_listeners,1,
                                [{file,"src/egs_app.erl"},{line,55}]},
                            {egs_app,start,2,
                                [{file,"src/egs_app.erl"},{line,38}]},
                            {application_master,start_it_old,4,
                                [{file,"application_master.erl"},
                                 {line,274}]}]}}}}
      type: temporary
  </code></pre>
  
  <p>Here are the files from which the errors originate.</p>
  
  <p>egs_patch_app.erl</p>
  
  <pre><code>-module(egs_patch_app).
  
  -behaviour(application).
  -export([start/2, stop/1]). %% API.
  
  -type application_start_type()
      :: normal | {takeover, node()} | {failover, node()}.
  
  %% API.
  
  -spec start(application_start_type(), term()) -&gt; {ok, pid()}.
  start(_Type, _StartArgs) -&gt;
      {ok, PatchPorts} = application:get_env(patch_ports),
      start_listeners(PatchPorts),
      egs_patch_sup:start_link().
  
  -spec stop(term()) -&gt; ok.
  stop(_State) -&gt;
      ok.
  
  %% Internal.
  
  -spec start_listeners([inet:ip_port()]) -&gt; ok.
  start_listeners([]) -&gt;
      ok;
  start_listeners([Port|Tail]) -&gt;
      {ok, _Pid} = cowboy:start_listener({patch, Port}, 10,
          cowboy_tcp_transport, [{port, Port}],
          egs_patch_protocol, []),
      start_listeners(Tail).
  </code></pre>
  
  <p>egs_app.erl</p>
  
  <pre><code>-module(egs_app).
  -behaviour(application).
  -export([start/2, stop/1]). %% API.
  -include("/home/mattk/Desktop/egs-master/apps/egs/include/records.hrl").
  
  -type application_start_type()
      :: normal | {takeover, node()} | {failover, node()}.
  
  -define(SSL_OPTIONS, [{certfile, "priv/ssl/servercert.pem"},
      {keyfile, "priv/ssl/serverkey.pem"}, {password, "alpha"}]).
  
  %% API.
  
  -spec start(application_start_type(), term()) -&gt; {ok, pid()}.
  start(_Type, _StartArgs) -&gt;
      {ok, Pid} = egs_sup:start_link(),
      application:set_env(egs_patch, patch_ports, egs_conf:read(patch_ports)),
      application:start(egs_patch),
      start_login_listeners(egs_conf:read(login_ports)),
      {_ServerIP, GamePort} = egs_conf:read(game_server),
      {ok, _GamePid} = cowboy:start_listener({game, GamePort}, 10,
          cowboy_ssl_transport, [{port, GamePort}] ++ ?SSL_OPTIONS,
          egs_game_protocol, []),
      {ok, Pid}.
  
  -spec stop(term()) -&gt; ok.
  stop(_State) -&gt;
      ok.
  
  %% Internal.
  
  -spec start_login_listeners([inet:ip_port()]) -&gt; ok.
  start_login_listeners([]) -&gt;
      ok;
  start_login_listeners([Port|Tail]) -&gt;
      {ok, _Pid} = cowboy:start_listener({login, Port}, 10,
          cowboy_ssl_transport, [{port, Port}] ++ ?SSL_OPTIONS,
          egs_login_protocol, []),
      start_login_listeners(Tail).
  </code></pre>