diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2014-07-28 15:52:21 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2014-07-28 15:52:21 +0100 |
| commit | 1142e5d0a3948178c37ff9118a606f864c63bc3a (patch) | |
| tree | 06141b6a9dad6d31a6b7971d2bc7e230e674ce6b | |
| parent | 8c1088a4be2fb28a6b681a3972e47223efea4712 (diff) | |
| download | rabbitmq-server-git-1142e5d0a3948178c37ff9118a606f864c63bc3a.tar.gz | |
Refactor: move ensure_app_running inside the big catch block, then we don't need to duplicate error handling.
| -rw-r--r-- | src/rabbit_control_main.erl | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl index 92712da9da..4f5a766cf4 100644 --- a/src/rabbit_control_main.erl +++ b/src/rabbit_control_main.erl @@ -145,19 +145,6 @@ start() -> end, Quiet = proplists:get_bool(?QUIET_OPT, Opts), Node = proplists:get_value(?NODE_OPT, Opts), - case lists:member(Command, ?COMMANDS_NOT_REQUIRING_APP) of - false -> - ensure_app_running(Node); - true -> - ok; - {badrpc, {'EXIT', Err}} -> - print_error("~p", [Err]), - rabbit_misc:quit(2); - {badrpc, Err} -> - print_error("unable to connect to node ~w: ~w", [Node, Err]), - print_badrpc_diagnostics([Node]), - rabbit_misc:quit(2) - end, Inform = case Quiet of true -> fun (_Format, _Args1) -> ok end; false -> fun (Format, Args1) -> @@ -172,7 +159,7 @@ start() -> %% The reason we don't use a try/catch here is that rpc:call turns %% thrown errors into normal return values - case catch action(Command, Node, Args, Opts, Inform) of + case catch do_action(Command, Node, Args, Opts, Inform) of ok -> case Quiet of true -> ok; @@ -267,6 +254,15 @@ parse_arguments(CmdLine, NodeStr) -> %%---------------------------------------------------------------------------- +do_action(Command, Node, Args, Opts, Inform) -> + case lists:member(Command, ?COMMANDS_NOT_REQUIRING_APP) of + false -> case ensure_app_running(Node) of + ok -> action(Command, Node, Args, Opts, Inform); + E -> E + end; + true -> action(Command, Node, Args, Opts, Inform) + end. + action(stop, Node, Args, _Opts, Inform) -> Inform("Stopping and halting node ~p", [Node]), Res = call(Node, {rabbit, stop_and_halt, []}), |
