diff options
author | Matthias Radestock <matthias@lshift.net> | 2008-11-30 11:35:14 +0000 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2008-11-30 11:35:14 +0000 |
commit | ef879d00c99a269bd40a5cd82c6f00f7f999f8cd (patch) | |
tree | 1336b08e528dca6f5a8c7f71b77614fb63cce8ea | |
parent | 0833b811241a9332828e1bbf7368a42b1012bd7a (diff) | |
download | rabbitmq-server-ef879d00c99a269bd40a5cd82c6f00f7f999f8cd.tar.gz |
improve error output
- consistently display errors as "Error: ..."
- display command and args properly formatted when encountering an
invalid command
-rw-r--r-- | src/rabbit_control.erl | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 2f7e58e0..4d77bb7d 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -35,23 +35,35 @@ start() -> FullCommand = init:get_plain_arguments(), #params{quiet = Quiet, node = Node, command = Command, args = Args} = - parse_args(FullCommand, #params{quiet = false, node = rabbit_misc:localnode(rabbit)}), + parse_args(FullCommand, #params{quiet = false, + node = rabbit_misc:localnode(rabbit)}), Inform = case Quiet of true -> fun(_Format, _Data) -> ok end; false -> fun io:format/2 end, + %% 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, Inform) of ok -> Inform("done.~n", []), init:stop(); {'EXIT', {function_clause, [{?MODULE, action, _} | _]}} -> - io:format("Error~nInvalid command ~p~n", [FullCommand]), + error("invalid command '~s'", + [lists:flatten( + rabbit_misc:intersperse( + " ", [atom_to_list(Command) | Args]))]), usage(); + {error, Reason} -> + error("~p", [Reason]), + halt(2); Other -> - io:format("Error~nrabbit_control action ~p failed:~n~p~n", [Command, Other]), + error("~p", [Other]), halt(2) end. +error(Format, Args) -> + io:format("Error: " ++ Format ++"~n", Args). + parse_args(["-n", NodeS | Args], Params) -> Node = case lists:member($@, NodeS) of true -> list_to_atom(NodeS); |