浏览代码

Manage syntax error in app.src files.

- Solve "Uncaught error" failure in case of syntax error in app.src file.
- Print helpful information on the location of the syntax error.
pull/394/head
Umberto Corponi 10 年前
父节点
当前提交
291e0de2fe
共有 2 个文件被更改,包括 17 次插入4 次删除
  1. +9
    -4
      src/rebar_app_discover.erl
  2. +8
    -0
      src/rebar_prv_app_discovery.erl

+ 9
- 4
src/rebar_app_discover.erl 查看文件

@ -159,7 +159,12 @@ find_app(AppDir, Validate) ->
case Validate of
V when V =:= invalid ; V =:= all ->
AppInfo = create_app_info(AppDir, File),
{true, rebar_app_info:app_file_src(AppInfo, File)};
case AppInfo of
{error, Reason} ->
throw({error, {invalid_app_file, File, Reason}});
_ ->
{true, rebar_app_info:app_file_src(AppInfo, File)}
end;
valid ->
false
end;
@ -175,7 +180,7 @@ find_app(AppDir, Validate) ->
app_dir(AppFile) ->
filename:join(rebar_utils:droplast(filename:split(filename:dirname(AppFile)))).
-spec create_app_info(file:name(), file:name()) -> rebar_app_info:t() | error.
-spec create_app_info(file:name(), file:name()) -> rebar_app_info:t() | {error, term()}.
create_app_info(AppDir, AppFile) ->
case file:consult(AppFile) of
{ok, [{application, AppName, AppDetails}]} ->
@ -193,8 +198,8 @@ create_app_info(AppDir, AppFile) ->
false
end,
rebar_app_info:dir(rebar_app_info:valid(AppInfo1, Valid), AppDir);
_ ->
error
{error, Reason} ->
{error, Reason}
end.
dedup([]) -> [];

+ 8
- 0
src/rebar_prv_app_discovery.erl 查看文件

@ -45,5 +45,13 @@ do(State) ->
-spec format_error(any()) -> iolist().
format_error({multiple_app_files, Files}) ->
io_lib:format("Multiple app files found in one app dir: ~s", [string:join(Files, " and ")]);
format_error({invalid_app_file, File, Reason}) ->
case Reason of
{Line, erl_parse, Description} ->
io_lib:format("Invalid app file ~s at line ~b: ~p",
[File, Line, lists:flatten(Description)]);
_ ->
io_lib:format("Invalid app file ~s: ~p", [File, Reason])
end;
format_error(Reason) ->
io_lib:format("~p", [Reason]).

正在加载...
取消
保存