4

我正在尝试运行自定义应用程序,但出现多个错误。我相信主要的 egs 应用程序会出错,因为它调用了未定义类型的 egs 补丁应用程序。我不知道如何让它工作我已经尝试过多次重新编译代码,以解决其他有类似问题的问题,但似乎没有任何效果。牛仔开始监听器仍未定义。

这是我收到的错误。

    =CRASH REPORT==== 10-Apr-2013::21:02:00 ===
  crasher:
    initial call: application_master:init/4
    pid: <0.106.0>
    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: [<0.105.0>]
    messages: [{'EXIT',<0.107.0>,normal}]
    links: [<0.105.0>,<0.7.0>]
    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: <0.75.0>
    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: [<0.74.0>]
    messages: [{'EXIT',<0.76.0>,normal}]
    links: [<0.74.0>,<0.7.0>]
    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

以下是产生错误的文件。

egs_patch_app.erl

-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()) -> {ok, pid()}.
start(_Type, _StartArgs) ->
    {ok, PatchPorts} = application:get_env(patch_ports),
    start_listeners(PatchPorts),
    egs_patch_sup:start_link().

-spec stop(term()) -> ok.
stop(_State) ->
    ok.

%% Internal.

-spec start_listeners([inet:ip_port()]) -> ok.
start_listeners([]) ->
    ok;
start_listeners([Port|Tail]) ->
    {ok, _Pid} = cowboy:start_listener({patch, Port}, 10,
        cowboy_tcp_transport, [{port, Port}],
        egs_patch_protocol, []),
    start_listeners(Tail).

egs_app.erl

-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()) -> {ok, pid()}.
start(_Type, _StartArgs) ->
    {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()) -> ok.
stop(_State) ->
    ok.

%% Internal.

-spec start_login_listeners([inet:ip_port()]) -> ok.
start_login_listeners([]) ->
    ok;
start_login_listeners([Port|Tail]) ->
    {ok, _Pid} = cowboy:start_listener({login, Port}, 10,
        cowboy_ssl_transport, [{port, Port}] ++ ?SSL_OPTIONS,
        egs_login_protocol, []),
    start_login_listeners(Tail).
4

1 回答 1

13

这是我们的提示:

  .....
  {{egs_patch_app,start,[normal,[]]},
      {'EXIT',
          {undef,
              [{cowboy,start_listener, .....

元组{egs_patch_app,start,[normal,[]]}告诉我们错误发生在egs_patch_app:start/2. atomEXIT是进程退出时发送的通知消息的标记,或者是诸如catch error(someerror). 现在我们进入有趣的部分。undef表示尝试调用未定义的函数。如果函数的名称/Arity 不匹配任何已知函数,则该函数是未定义的。在这种情况下,未定义的函数是cowboy:start_listener().

再一次,问题是 Cowboy 已经进化,而 egs 没有。Cowboy API 的重大变化使两者不兼容。由于 egs 的最后一次更改是大约一年前(假设您使用的是 essen 的分支),您可以尝试通过将相应的rebar.config行更改为如下内容来恢复到较旧的 Cowboy 标签:

{cowboy, ".*", {git, "git://github.com/extend/cowboy.git", {tag, "0.6.0"}}

注意如何"HEAD"更改为{tag, "0.6.0"}. Cowboy 引用可能必须在多个应用程序中更改(至少egsegs_patch)。您很可能需要先清除deps/


Erlang 错误消息可能难以解析,但作为一般经验法则,您应该注意一些原子:

  • case_clause, 表示case表达式中没有匹配的子句。
  • function_clause, 表示没有函数子句与参数匹配。
  • undef,如上所述,这意味着无法解析对外部(不是模块本地)函数的调用。
  • badarg,这是 Erlang 的“非法参数”例外。
  • badarith,当您在算术表达式中将变量名称错误键入为原子时,有时会出现这种鬼鬼祟祟的混蛋,例如1/x代替1/X.

要了解有关 Erlang 错误处理机制的更多信息,请阅读文档

于 2013-04-11T07:35:25.237 回答