summaryrefslogtreecommitdiff
path: root/src/rebar_provider.erl
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2014-09-27 14:12:11 -0500
committerTristan Sloughter <t@crashfast.com>2014-09-27 14:12:11 -0500
commite9a3396e56679a11ac1caa3b47f1f196f0307d72 (patch)
tree0fca145d934313ebfdc45565a78ed9d3ff99f948 /src/rebar_provider.erl
parent1549b11b88dca340a1e471775d8387ca94e377e5 (diff)
return error messages from providers
Diffstat (limited to 'src/rebar_provider.erl')
-rw-r--r--src/rebar_provider.erl27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/rebar_provider.erl b/src/rebar_provider.erl
index 872c2e1..7d78e3b 100644
--- a/src/rebar_provider.erl
+++ b/src/rebar_provider.erl
@@ -23,7 +23,7 @@
-type provider_name() :: atom().
-callback init(rebar_state:t()) -> {ok, rebar_state:t()}.
--callback do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-callback do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
%%%===================================================================
%%% API
@@ -59,20 +59,21 @@ create(Attrs) ->
%%
%% @param Provider the provider object
%% @param State the current state of the system
--spec do(Provider::t(), rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(Provider::t(), rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(Provider, State) ->
{PreHooks, PostHooks} = rebar_state:hooks(State, Provider#provider.name),
- {ok, State1} = run_hook_plugins(PreHooks, State),
- {ok, State2} = (Provider#provider.provider_impl):do(State1),
- run_hook_plugins(PostHooks, State2).
-
--spec run_hook_plugins([t()], rebar_state:t()) -> {ok, rebar_state:t()}.
-run_hook_plugins(Hooks, State) ->
- State1 = lists:foldl(fun(Hook, StateAcc) ->
- {ok, StateAcc1} = rebar_provider:do(Hook, StateAcc),
- StateAcc1
- end, State, Hooks),
- {ok, State1}.
+ run_all([PreHooks++Provider | PostHooks], State).
+
+-spec run_all([t()], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
+run_all([], State) ->
+ {ok, State};
+run_all([Provider | Rest], State) ->
+ case (Provider#provider.provider_impl):do(State) of
+ {ok, State1} ->
+ run_all(Rest, State1);
+ {error, Error} ->
+ {error, Error}
+ end.
%%% @doc get the name of the module that implements the provider
%%% @param Provider the provider object