From fa52e19b4990a17eb7efbafc0364c0c686d7b770 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 22 Oct 2012 12:42:58 -0500 Subject: fix error reporting when using the erlang API Signed-off-by: Jordan Wilberding --- src/rcl_state.erl | 14 +++++++++++++- src/relcool.erl | 17 ++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/rcl_state.erl b/src/rcl_state.erl index 23c7e74..c326df1 100644 --- a/src/rcl_state.erl +++ b/src/rcl_state.erl @@ -91,7 +91,7 @@ new(PropList, Targets) when erlang:is_list(PropList) -> #state_t{log = proplists:get_value(log, PropList, rcl_log:new(error)), output_dir=filename:absname(proplists:get_value(output_dir, PropList, "")), lib_dirs=get_lib_dirs(proplists:get_value(lib_dirs, PropList, [])), - config_files=Targets, + config_files=handle_configs(Targets), goals=proplists:get_value(goals, PropList, []), providers = [], releases=ec_dictionary:new(ec_dict), @@ -252,6 +252,18 @@ create_logic_providers(State0) -> State4#state_t{providers=[ConfigProvider, DiscoveryProvider, ReleaseProvider, AssemblerProvider]}. + +%% @doc explicitly handle single config file path +-spec handle_configs(string() | [string()]) -> [string()]. +handle_configs(Configs = [Config | _]) + when erlang:is_list(Config) -> + Configs; +handle_configs(Config = [Char | _]) + when erlang:is_integer(Char) -> + [Config]; +handle_configs([]) -> + []. + %%%=================================================================== %%% Test Functions %%%=================================================================== diff --git a/src/relcool.erl b/src/relcool.erl index 9e143a6..98b84f7 100644 --- a/src/relcool.erl +++ b/src/relcool.erl @@ -43,7 +43,12 @@ main(Args) -> OptSpecList = opt_spec_list(), case rcl_cmd_args:args2state(getopt:parse(OptSpecList, Args)) of {ok, {State, _Target}} -> - run_relcool_process(rcl_state:caller(State, command_line)); + case run_relcool_process(rcl_state:caller(State, command_line)) of + Result = {ok, _} -> + Result; + Error={error, _} -> + report_error(State, Error) + end; Error={error, _} -> report_error(rcl_state:caller(rcl_state:new([], []), command_line), Error) @@ -77,13 +82,16 @@ opt_spec_list() -> "usually the OTP"}, {output_dir, $o, "output-dir", string, "The output directory for the release. This is `./` by default."}, {lib_dir, $l, "lib-dir", string, "Additional dirs that should be searched for OTP Apps"}, - {log_level, $V, "verbose", {integer, 1}, "Verbosity level, maybe between 0 and 2"} + {log_level, $V, "verbose", {integer, 2}, "Verbosity level, maybe between 0 and 2"} ]. -spec format_error(Reason::term()) -> iolist(). format_error({invalid_return_value, Provider, Value}) -> [rcl_provider:format(Provider), " returned an invalid value ", - io_lib:format("~p", [Value])]. + io_lib:format("~p", [Value])]; +format_error({error, {Module, Reason}}) -> + io_lib:format("~s", [Module:format_error(Reason)]). + %%============================================================================ %% internal api @@ -136,14 +144,13 @@ run_provider(Provider, {ok, State0}) -> {ok, State1} -> {ok, State1}; E={error, _} -> - report_error(State0, E) + E end. -spec usage() -> ok. usage() -> getopt:usage(opt_spec_list(), "relcool", "[*release-specification-file*]"). - -spec report_error(rcl_state:t(), error()) -> none() | error(). report_error(State, Error={error, {Module, Reason}}) -> io:format("~s~n", [Module:format_error(Reason)]), -- cgit v1.2.3