summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2015-05-22 10:36:41 -0500
committerTristan Sloughter <t@crashfast.com>2015-05-22 10:36:51 -0500
commit8528204431b609c14288098be5dea83676b59ec9 (patch)
tree7a1f4fd5bdecd00c2f9c12f9ab9e9932fcf275de /src
parentb7acb56f4710fe3fd11163f6874f82f0008625b6 (diff)
print and format error message for bad .app files and all bad configs
Diffstat (limited to 'src')
-rw-r--r--src/rebar_app_discover.erl34
-rw-r--r--src/rebar_app_info.erl7
-rw-r--r--src/rebar_config.erl14
-rw-r--r--src/rebar_file_utils.erl18
-rw-r--r--src/rebar_prv_app_discovery.erl11
-rw-r--r--src/rebar_prv_dialyzer.erl4
-rw-r--r--src/rebar_prv_shell.erl21
7 files changed, 51 insertions, 58 deletions
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl
index 4eda199..34310c7 100644
--- a/src/rebar_app_discover.erl
+++ b/src/rebar_app_discover.erl
@@ -182,25 +182,21 @@ app_dir(AppFile) ->
-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}]} ->
- AppVsn = proplists:get_value(vsn, AppDetails),
- Applications = proplists:get_value(applications, AppDetails, []),
- IncludedApplications = proplists:get_value(included_applications, AppDetails, []),
- {ok, AppInfo} = rebar_app_info:new(AppName, AppVsn, AppDir, []),
- AppInfo1 = rebar_app_info:applications(
- rebar_app_info:app_details(AppInfo, AppDetails),
- IncludedApplications++Applications),
- Valid = case rebar_app_utils:validate_application_info(AppInfo1) of
- true ->
- true;
- _ ->
- false
- end,
- rebar_app_info:dir(rebar_app_info:valid(AppInfo1, Valid), AppDir);
- {error, Reason} ->
- {error, Reason}
- end.
+ [{application, AppName, AppDetails}] = rebar_file_utils:try_consult(AppFile),
+ AppVsn = proplists:get_value(vsn, AppDetails),
+ Applications = proplists:get_value(applications, AppDetails, []),
+ IncludedApplications = proplists:get_value(included_applications, AppDetails, []),
+ {ok, AppInfo} = rebar_app_info:new(AppName, AppVsn, AppDir, []),
+ AppInfo1 = rebar_app_info:applications(
+ rebar_app_info:app_details(AppInfo, AppDetails),
+ IncludedApplications++Applications),
+ Valid = case rebar_app_utils:validate_application_info(AppInfo1) of
+ true ->
+ true;
+ _ ->
+ false
+ end,
+ rebar_app_info:dir(rebar_app_info:valid(AppInfo1, Valid), AppDir).
dedup([]) -> [];
dedup([A]) -> [A];
diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl
index 247e5f4..382ea7a 100644
--- a/src/rebar_app_info.erl
+++ b/src/rebar_app_info.erl
@@ -167,12 +167,7 @@ app_details(AppInfo=#app_info_t{app_details=[]}) ->
File ->
File
end,
- case file:consult(AppFile) of
- {ok, [{application, _, AppDetails}]} ->
- AppDetails;
- _ ->
- []
- end;
+ rebar_file_utils:try_consult(AppFile);
app_details(#app_info_t{app_details=AppDetails}) ->
AppDetails.
diff --git a/src/rebar_config.erl b/src/rebar_config.erl
index c858fef..b8222bc 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -57,7 +57,7 @@ consult_file(File) ->
{ok, Terms} = consult_and_eval(File, Script),
Terms;
false ->
- try_consult(File)
+ rebar_file_utils:try_consult(File)
end
end.
@@ -87,22 +87,12 @@ format_error({bad_dep_name, Dep}) ->
consult_and_eval(File, Script) ->
?DEBUG("Evaluating config script ~p", [Script]),
- StateData = try_consult(File),
+ StateData = rebar_file_utils:try_consult(File),
file:script(Script, bs([{'CONFIG', StateData}, {'SCRIPT', Script}])).
remove_script_ext(F) ->
filename:rootname(F, ".script").
-try_consult(File) ->
- case file:consult(File) of
- {ok, Terms} ->
- Terms;
- {error, enoent} ->
- [];
- {error, Reason} ->
- ?ABORT("Failed to read config file ~s:~n ~p", [File, Reason])
- end.
-
bs(Vars) ->
lists:foldl(fun({K,V}, Bs) ->
erl_eval:add_binding(K, V, Bs)
diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl
index ef2c70f..ad30172 100644
--- a/src/rebar_file_utils.erl
+++ b/src/rebar_file_utils.erl
@@ -26,7 +26,9 @@
%% -------------------------------------------------------------------
-module(rebar_file_utils).
--export([symlink_or_copy/2,
+-export([try_consult/1,
+ format_error/1,
+ symlink_or_copy/2,
rm_rf/1,
cp_r/2,
mv/2,
@@ -37,11 +39,25 @@
reset_dir/1]).
-include("rebar.hrl").
+-include_lib("providers/include/providers.hrl").
%% ===================================================================
%% Public API
%% ===================================================================
+try_consult(File) ->
+ case file:consult(File) of
+ {ok, Terms} ->
+ Terms;
+ {error, enoent} ->
+ [];
+ {error, Reason} ->
+ throw(?PRV_ERROR({bad_term_file, File, Reason}))
+ end.
+
+format_error({bad_term_file, AppFile, Reason}) ->
+ io_lib:format("Error reading file ~s: ~s", [AppFile, file:format_error(Reason)]).
+
symlink_or_copy(Source, Target) ->
Link = case os:type() of
{win32, _} ->
diff --git a/src/rebar_prv_app_discovery.erl b/src/rebar_prv_app_discovery.erl
index 97862c1..0e53bb4 100644
--- a/src/rebar_prv_app_discovery.erl
+++ b/src/rebar_prv_app_discovery.erl
@@ -38,7 +38,7 @@ do(State) ->
State1 = rebar_app_discover:do(State, LibDirs),
{ok, State1}
catch
- throw:{error, Error}->
+ throw:{error, Error} ->
?PRV_ERROR(Error)
end.
@@ -46,12 +46,17 @@ do(State) ->
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
+ case Reason of
{Line, erl_parse, Description} ->
- io_lib:format("Invalid app file ~s at line ~b: ~p",
+ 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;
+%% Provide a slightly more informative error message for consult of app file failure
+format_error({rebar_file_utils, {bad_term_file, AppFile, Reason}}) ->
+ io_lib:format("Error in app file ~s: ~s", [rebar_dir:make_relative_path(AppFile,
+ rebar_dir:get_cwd()),
+ file:format_error(Reason)]);
format_error(Reason) ->
io_lib:format("~p", [Reason]).
diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl
index 96e2277..95529f8 100644
--- a/src/rebar_prv_dialyzer.erl
+++ b/src/rebar_prv_dialyzer.erl
@@ -237,8 +237,8 @@ ebin_to_info(EbinDir, AppName) ->
{IncApps ++ DepApps, Files, Warnings};
{error, enoent} when AppName =:= erts ->
{[], ebin_files(EbinDir), []};
- _ ->
- Error = io_lib:format("Could not parse ~p", [AppFile]),
+ {error, Reason} ->
+ Error = io_lib:format("Could not parse ~s: ~p", [AppFile, file:format_error(Reason)]),
throw({dialyzer_error, Error})
end.
diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl
index ec2f692..8c0b7ff 100644
--- a/src/rebar_prv_shell.erl
+++ b/src/rebar_prv_shell.erl
@@ -136,20 +136,18 @@ reread_config(State) ->
case find_config(State) of
no_config ->
ok;
- {ok, ConfigList} ->
+ ConfigList ->
lists:foreach(fun ({Application, Items}) ->
lists:foreach(fun ({Key, Val}) ->
application:set_env(Application, Key, Val)
end,
Items)
end,
- ConfigList);
- {error, Error} ->
- ?ABORT("Error while attempting to read configuration file: ~p", [Error])
+ ConfigList)
end.
% First try the --config flag, then try the relx sys_config
--spec find_config(rebar_state:t()) -> {ok, [tuple()]}|no_config|{error, tuple()}.
+-spec find_config(rebar_state:t()) -> [tuple()] | no_config.
find_config(State) ->
case find_config_option(State) of
no_config ->
@@ -158,7 +156,7 @@ find_config(State) ->
Result
end.
--spec find_config_option(rebar_state:t()) -> {ok, [tuple()]}|no_config|{error, tuple()}.
+-spec find_config_option(rebar_state:t()) -> [tuple()] | no_config.
find_config_option(State) ->
{Opts, _} = rebar_state:command_parsed_args(State),
case proplists:get_value(config, Opts) of
@@ -168,7 +166,7 @@ find_config_option(State) ->
consult_config(State, Filename)
end.
--spec find_config_relx(rebar_state:t()) -> {ok, [tuple()]}|no_config|{error, tuple()}.
+-spec find_config_relx(rebar_state:t()) -> [tuple()] | no_config.
find_config_relx(State) ->
case proplists:get_value(sys_config, rebar_state:get(State, relx, [])) of
undefined ->
@@ -181,11 +179,4 @@ find_config_relx(State) ->
consult_config(State, Filename) ->
Fullpath = filename:join(rebar_dir:root_dir(State), Filename),
?DEBUG("Loading configuration from ~p", [Fullpath]),
- case file:consult(Fullpath) of
- {ok, [Config]} ->
- {ok, Config};
- {ok, []} ->
- {ok, []};
- {error, Error} ->
- {error, {Error, Fullpath}}
- end.
+ rebar_file_utils:try_consult(Fullpath).