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 | be20e10699c6254b0cd1be48754419e50bf24af4 (patch) | |
| tree | 1336b08e528dca6f5a8c7f71b77614fb63cce8ea /src | |
| parent | 1be524ca099a8a2890321a42e5da2284995078bc (diff) | |
| download | rabbitmq-server-git-be20e10699c6254b0cd1be48754419e50bf24af4.tar.gz | |
improve error output
- consistently display errors as "Error: ..."
- display command and args properly formatted when encountering an
invalid command
Diffstat (limited to 'src')
| -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 2f7e58e0b5..4d77bb7df9 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); |
