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 | 3a4dc20f637c715b6b8edbf064e6fc3d7017be90 (patch) | |
tree | 06141b6a9dad6d31a6b7971d2bc7e230e674ce6b | |
parent | 6e7793148d7e8fe2d1290e030b22f8593daaaad8 (diff) | |
download | rabbitmq-server-3a4dc20f637c715b6b8edbf064e6fc3d7017be90.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 92712da9..4f5a766c 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, []}), |