Erlang退出原因 - undef(带字符串:find / 2 func)

时间:2017-12-26 12:33:29

标签: erlang

尝试使用函数string:find/2,但每次都会收到错误

CRASH REPORT Process <0.779.0> with 0 neighbours exited with reason: {{undef,[{string,find,[[<<208,162,51,32,208,190,208,177,209,137,46,44,32,84,51,32,116,111,116,97,108,44>>],[<<208,186,209,128,208,190,208,178>>]],[]},{proxy_layer_cli_handle_req,do_execute_keysearch,4,[{file,\"/opt/proxy_layer/_build/test/lib/proxy_layer/src/proxy_layer_cli_handle_req.erl\"},{line,222}]},{proxy_layer_cli_handle_req,keysearch,3,[{file,\"/opt/proxy_layer/_build/test/lib/proxy_layer/src/proxy_layer_cli_handle_req.erl\"},{line,...}]},...]},...}

当我在终端使用它时 - 一切都很好

1> string:find(<<208,162,51,32,208,190,208,177,209,137,46,44,32,84,51,32,116,111,116,97,108,44>>,<<208,186,209,128,208,190,208,178>>).     
1> nomatch

我正在使用Erlang 20.1

这是我使用的代码:

do_execute_keysearch([First|Rest], PriceList, Keyword, Acc) ->
  Id = utils:get_value(<<"Id">>, First),
  case utils:get_value(<<"Keywords">>, First) of
    <<>> -> do_execute_keysearch(Rest, PriceList, Keyword, Acc);
    undefined -> do_execute_keysearch(Rest, PriceList, Keyword, Acc);
    Keys ->
      case string:find(Keys, Keyword) of
        nomatch ->
          do_execute_keysearch(Rest, PriceList, Keyword, Acc);
        _ ->
          Price = find_price_by_service_id(PriceList, Id),
          NewAcc = [lists:append(Price, First) | Acc],
          do_execute_keysearch(Rest, PriceList, Keyword, NewAcc)
      end
    end;

更新: 在docker容器中更改Erlang版本后修复了问题。 (改为Erlang 20.1) 不知道为什么Erlang 19中有一些模块未定义

所以问题现在解决了

2 个答案:

答案 0 :(得分:1)

string:find/2 was added to Erlang in version 20这就是您在Erlang 19中收到undef错误的原因。解决方法是升级到Erlang 20(您已经完成了)。< / p>

答案 1 :(得分:-2)

更仔细地查看错误。或者更确切地说,尝试重现它。哪一个看起来更像你的错误?

1> catch lists:nonexist(<<1>>, <<2>>).
{'EXIT',{undef,[{lists,nonexist,[<<1>>,<<2>>],[]},
                {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,674}]},
                {erl_eval,expr,5,[{file,"erl_eval.erl"},{line,431}]},
                {shell,exprs,7,[{file,"shell.erl"},{line,687}]},
                {shell,eval_exprs,7,[{file,"shell.erl"},{line,642}]},
                {shell,eval_loop,3,[{file,"shell.erl"},{line,627}]}]}}
2> catch lists:nonexist([<<1>>], [<<2>>]).
{'EXIT',{undef,[{lists,nonexist,[[<<1>>],[<<2>>]],[]},
                {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,674}]},
                {erl_eval,expr,5,[{file,"erl_eval.erl"},{line,431}]},
                {shell,exprs,7,[{file,"shell.erl"},{line,687}]},
                {shell,eval_exprs,7,[{file,"shell.erl"},{line,642}]},
                {shell,eval_loop,3,[{file,"shell.erl"},{line,627}]}]}}