aboutsummaryrefslogtreecommitdiffstats
path: root/src/rcl_prv_config.erl
diff options
context:
space:
mode:
authorEric <[email protected]>2012-09-18 15:51:47 -0700
committerEric <[email protected]>2012-09-18 15:51:47 -0700
commit49a45620c2c0431583969192fbefe44ee6f7850c (patch)
tree5f7624b3473797637f711bc0f345b7290b4a92b4 /src/rcl_prv_config.erl
parent79a28e0e498c4727dde2546ff83da6cb81e907e6 (diff)
downloadrelx-49a45620c2c0431583969192fbefe44ee6f7850c.tar.gz
relx-49a45620c2c0431583969192fbefe44ee6f7850c.tar.bz2
relx-49a45620c2c0431583969192fbefe44ee6f7850c.zip
make sure errors carry the name of the module that created them
This allows errors to be printed at the source
Diffstat (limited to 'src/rcl_prv_config.erl')
-rw-r--r--src/rcl_prv_config.erl38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/rcl_prv_config.erl b/src/rcl_prv_config.erl
index 3b92a3b..5d97ce5 100644
--- a/src/rcl_prv_config.erl
+++ b/src/rcl_prv_config.erl
@@ -14,32 +14,35 @@
do/1,
format_error/1]).
+-include_lib("relcool/include/relcool.hrl").
%%%===================================================================
%%% API
%%%===================================================================
%% @doc Required by the system, but not used in this provider
--spec init(rcl_state:t()) -> {ok, rcl_state:t()} | {error, Reason::term()}.
+-spec init(rcl_state:t()) -> {ok, rcl_state:t()} | relcool:error().
init(State) ->
{ok, State}.
%% @doc parse all the configs currently specified in the state,
%% populating the state as a result.
--spec do(rcl_state:t()) ->{ok, rcl_state:t()} | {error, Reason::term()}.
+-spec do(rcl_state:t()) ->{ok, rcl_state:t()} | relcool:error().
do(State) ->
ConfigFiles = rcl_state:config_files(State),
lists:foldl(fun load_config/2, {ok, State}, ConfigFiles).
--spec format_error({error, Reason::term()}) -> iolist().
-format_error({error, {consult, Reason}}) ->
+-spec format_error(Reason::term()) -> iolist().
+format_error({consult, Reason}) ->
file:format_error(Reason);
-format_error({error, {invalid_term, Term}}) ->
+format_error({invalid_term, Term}) ->
io_lib:format("Invalid term in config file: ~p", [Term]).
%%%===================================================================
%%% Internal Functions
%%%===================================================================
+-spec load_config(file:filename(), {ok, rcl_state:t()} | relcool:error()) ->
+ {ok, rcl_state:t()} | relcool:error().
load_config(_, Err = {error, _}) ->
Err;
load_config(ConfigFile, {ok, State}) ->
@@ -47,13 +50,15 @@ load_config(ConfigFile, {ok, State}) ->
ok = file:set_cwd(filename:dirname(ConfigFile)),
Result = case file:consult(ConfigFile) of
{error, Reason} ->
- {error, {consult, Reason}};
+ ?RCL_ERROR({consult, Reason});
{ok, Terms} ->
lists:foldl(fun load_terms/2, {ok, State}, Terms)
end,
ok = file:set_cwd(CurrentCwd),
Result.
+-spec load_terms(term(), {ok, rcl_state:t()} | relcool:error()) ->
+ {ok, rcl_state:t()} | relcool:error().
load_terms({default_release, RelName, RelVsn}, {ok, State}) ->
{ok, rcl_state:default_release(State, RelName, RelVsn)};
load_terms({paths, Paths}, {ok, State}) ->
@@ -62,16 +67,16 @@ load_terms({paths, Paths}, {ok, State}) ->
load_terms({providers, Providers0}, {ok, State0}) ->
Providers1 = gen_providers(Providers0, State0),
case Providers1 of
- {error, _} ->
- Providers1;
+ {_, E={error, _}} ->
+ E;
{Providers3, {ok, State3}} ->
{ok, rcl_state:providers(State3, Providers3)}
end;
load_terms({add_providers, Providers0}, {ok, State0}) ->
Providers1 = gen_providers(Providers0, State0),
case Providers1 of
- {error, _} ->
- Providers1;
+ {_, E={error, _}} ->
+ E;
{Providers3, {ok, State1}} ->
ExistingProviders = rcl_state:providers(State1),
{ok, rcl_state:providers(State1, ExistingProviders ++ Providers3)}
@@ -80,7 +85,7 @@ load_terms({add_providers, Providers0}, {ok, State0}) ->
load_terms({release, {RelName, Vsn}, Applications}, {ok, State0}) ->
Release0 = rcl_release:new(RelName, Vsn),
case rcl_release:goals(Release0, Applications) of
- E = {error, _} ->
+ {_, E={error, _}} ->
E;
{ok, Release1} ->
{ok, rcl_state:add_release(State0, Release1)}
@@ -89,7 +94,7 @@ load_terms({release, {RelName, Vsn}, {erts, ErtsVsn},
Applications}, {ok, State}) ->
Release0 = rcl_release:erts(rcl_release:new(RelName, Vsn), ErtsVsn),
case rcl_release:goals(Release0, Applications) of
- E = {error, _} ->
+ {_, E={error, _}} ->
E;
{ok, Release1} ->
{ok, rcl_state:add_release(State, Release1)}
@@ -97,14 +102,17 @@ load_terms({release, {RelName, Vsn}, {erts, ErtsVsn},
load_terms({Name, Value}, {ok, State})
when erlang:is_atom(Name) ->
{ok, rcl_state:put(State, Name, Value)};
+load_terms(_, Error={error, _}) ->
+ Error;
load_terms(InvalidTerm, _) ->
- {error, {invalid_term, InvalidTerm}}.
-
+ ?RCL_ERROR({invalid_term, InvalidTerm}).
+-spec gen_providers([module()], rcl_state:t()) ->
+ {[rcl_provider:t()], {ok, rcl_state:t()} | relcool:error()}.
gen_providers(Providers, State) ->
lists:foldl(fun(ProviderName, {Providers1, {ok, State1}}) ->
{Provider, State2} = rcl_provider:new(ProviderName, State1),
{[Provider | Providers1], State2};
- (_, E={error, _}) ->
+ (_, E={_, {error, _}}) ->
E
end, {[], {ok, State}}, Providers).