From 317eeb72e0e4a6855910a7ac26295735ccb77553 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Thu, 8 Sep 2011 22:52:21 +0200 Subject: [PATCH] Fix Dialyzer warning --- README.md | 1 - src/rebar_utils.erl | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3e76121..78a6cd4 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,6 @@ The following discrepancies are known and safe to ignore: ``` rebar_utils.erl:147: Call to missing or unexported function escript:foldl/3 -rebar_utils.erl:180: The created fun has no local return ``` It is **strongly recommended** to check the code with diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index e19911b..4148160 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -105,7 +105,7 @@ sh(Command0, Options0) -> case sh_loop(Port, OutputHandler, []) of {ok, _Output} = Ok -> Ok; - {error, Err} -> + {error, {_Rc, _Output}=Err} -> ErrorHandler(Command, Err) end. @@ -211,9 +211,7 @@ expand_sh_flag(return_on_error) -> end}; expand_sh_flag({abort_on_error, Message}) -> {error_handler, - fun(_Command, _Err) -> - ?ABORT(Message, []) - end}; + log_msg_and_abort(Message)}; expand_sh_flag(abort_on_error) -> {error_handler, fun log_and_abort/2}; @@ -233,9 +231,17 @@ expand_sh_flag({cd, _CdArg} = Cd) -> expand_sh_flag({env, _EnvArg} = Env) -> {port_settings, Env}. --spec log_and_abort(string(), integer()) -> no_return(). +-type err_handler() :: fun((string(), {integer(), string()}) -> no_return()). +-spec log_msg_and_abort(string()) -> err_handler(). +log_msg_and_abort(Message) -> + fun(_Command, {_Rc, _Output}) -> + ?ABORT(Message, []) + end. + +-spec log_and_abort(string(), {integer(), string()}) -> no_return(). log_and_abort(Command, {Rc, Output}) -> - ?ABORT("~s failed with error: ~w and output:~n~s~n", [Command, Rc, Output]). + ?ABORT("~s failed with error: ~w and output:~n~s~n", + [Command, Rc, Output]). sh_loop(Port, Fun, Acc) -> receive