diff options
author | Eric <[email protected]> | 2012-09-18 15:51:47 -0700 |
---|---|---|
committer | Eric <[email protected]> | 2012-09-18 15:51:47 -0700 |
commit | 49a45620c2c0431583969192fbefe44ee6f7850c (patch) | |
tree | 5f7624b3473797637f711bc0f345b7290b4a92b4 /src/rcl_app_info.erl | |
parent | 79a28e0e498c4727dde2546ff83da6cb81e907e6 (diff) | |
download | relx-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_app_info.erl')
-rw-r--r-- | src/rcl_app_info.erl | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/rcl_app_info.erl b/src/rcl_app_info.erl index 4d91961..db32a8f 100644 --- a/src/rcl_app_info.erl +++ b/src/rcl_app_info.erl @@ -42,6 +42,7 @@ name/2, vsn/1, vsn/2, + vsn_as_string/1, dir/1, dir/2, active_deps/1, @@ -54,6 +55,8 @@ -export_type([t/0]). +-include_lib("relcool/include/relcool.hrl"). + -record(app_info_t, {name :: atom(), vsn :: ec_semver:semver(), dir :: file:name(), @@ -76,7 +79,7 @@ new() -> %% @doc build a complete version of the app info with all fields set. -spec new(atom(), string(), file:name(), [atom()], [atom()]) -> - {ok, t()} | {error, Reason::term()}. + {ok, t()} | relcool:error(). new(AppName, Vsn, Dir, ActiveDeps, LibraryDeps) when erlang:is_atom(AppName), erlang:is_list(Dir), @@ -84,7 +87,7 @@ new(AppName, Vsn, Dir, ActiveDeps, LibraryDeps) erlang:is_list(LibraryDeps) -> case parse_version(Vsn) of {fail, _} -> - {error, {vsn_parse, AppName}}; + ?RCL_ERROR({vsn_parse, AppName}); ParsedVsn -> {ok, #app_info_t{name=AppName, vsn=ParsedVsn, dir=Dir, active_deps=ActiveDeps, @@ -104,17 +107,20 @@ name(AppInfo=#app_info_t{}, AppName) vsn(#app_info_t{vsn=Vsn}) -> Vsn. --spec vsn(t(), string()) -> {ok, t()} | {error, Reason::term()}. +-spec vsn_as_string(t()) -> string(). +vsn_as_string(#app_info_t{vsn=Vsn}) -> + erlang:binary_to_list(erlang:iolist_to_binary(ec_semver:format(Vsn))). + +-spec vsn(t(), string()) -> {ok, t()} | relcool:error(). vsn(AppInfo=#app_info_t{name=AppName}, AppVsn) when erlang:is_list(AppVsn) -> case parse_version(AppVsn) of {fail, _} -> - {error, {vsn_parse, AppName}}; + ?RCL_ERROR({vsn_parse, AppName}); ParsedVsn -> {ok, AppInfo#app_info_t{vsn=ParsedVsn}} end. - -spec dir(t()) -> file:name(). dir(#app_info_t{dir=Dir}) -> Dir. @@ -139,10 +145,10 @@ library_deps(AppInfo=#app_info_t{}, LibraryDeps) when erlang:is_list(LibraryDeps) -> AppInfo#app_info_t{library_deps=LibraryDeps}. --spec format_error({error, Reason::term()}) -> iolist(). -format_error({error, {vsn_parse, AppName, AppDir}}) -> - io_lib:format("Error parsing version for ~p at ~s", - [AppName, AppDir]). +-spec format_error(Reason::term()) -> iolist(). +format_error({vsn_parse, AppName}) -> + io_lib:format("Error parsing version for ~p", + [AppName]). -spec format(t()) -> iolist(). format(AppInfo) -> @@ -158,8 +164,6 @@ format(Indent, #app_info_t{name=Name, vsn=Vsn, dir=Dir, rcl_util:indent(Indent + 1), "Library Dependencies:\n", [[rcl_util:indent(Indent + 2), erlang:atom_to_list(LibDep), ",\n"] || LibDep <- LibDeps]]. - - %%%=================================================================== %%% Internal Functions %%%=================================================================== |