diff options
author | Matthias Radestock <matthias@lshift.net> | 2009-09-19 05:47:05 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2009-09-19 05:47:05 +0100 |
commit | 078735c3b9379317f8f9153d20ba2a25c7c68e7d (patch) | |
tree | f53d8a02c1b8f39ca9b8d99ef4ab730fef0d362c | |
parent | b3d2c95c772885a8127d62cb314c97f5834191d7 (diff) | |
download | rabbitmq-server-078735c3b9379317f8f9153d20ba2a25c7c68e7d.tar.gz |
minor, mostly cosmetic, tweaks
-rw-r--r-- | include/rabbit.hrl | 2 | ||||
-rw-r--r-- | src/rabbit_channel.erl | 7 | ||||
-rw-r--r-- | src/rabbit_misc.erl | 19 | ||||
-rw-r--r-- | src/rabbit_reader.erl | 36 |
4 files changed, 30 insertions, 34 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl index fbe598cc..84a1d4f7 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -67,7 +67,7 @@ -record(ssl_socket, {tcp, ssl}). -record(delivery, {mandatory, immediate, txn, sender, message}). --record(amqp_error, {name, expl = "", method = none}). +-record(amqp_error, {name, expl, method = none}). %%---------------------------------------------------------------------------- diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 812b317a..a1fa1066 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -127,10 +127,9 @@ handle_cast({method, Method, Content}, State) -> catch exit:Reason = #amqp_error{} -> ok = rollback_and_notify(State), - CompleteReason = Reason#amqp_error{method = - rabbit_misc:method_record_type(Method)}, - State#ch.reader_pid ! - {channel_exit, State#ch.channel, CompleteReason}, + MethodName = rabbit_misc:method_record_type(Method), + State#ch.reader_pid ! {channel_exit, State#ch.channel, + Reason#amqp_error{method = MethodName}}, {stop, normal, State#ch{state = terminating}}; exit:normal -> {stop, normal, State}; diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index fc8d1381..7e15dfe8 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -35,7 +35,8 @@ -include_lib("kernel/include/file.hrl"). -export([method_record_type/1, polite_pause/0, polite_pause/1]). --export([die/1, frame_error/2, amqp_error/4, protocol_error/3, protocol_error/4]). +-export([die/1, frame_error/2, amqp_error/4, + protocol_error/3, protocol_error/4]). -export([not_found/1]). -export([get_config/1, get_config/2, set_config/2]). -export([dirty_read/1]). @@ -145,15 +146,15 @@ die(Error) -> frame_error(MethodName, BinaryFields) -> protocol_error(frame_error, "cannot decode ~w", [BinaryFields], MethodName). -amqp_error(Name, Explanation, Params, Method) -> - #amqp_error{name = Name, - expl = lists:flatten(io_lib:format(Explanation, Params)), - method = Method}. +amqp_error(Name, ExplanationFormat, Params, Method) -> + Explanation = lists:flatten(io_lib:format(ExplanationFormat, Params)), + #amqp_error{name = Name, expl = Explanation, method = Method}. -protocol_error(Name, Explanation, Params) -> - protocol_error(Name, Explanation, Params, none). -protocol_error(Name, Explanation, Params, Method) -> - exit(amqp_error(Name, Explanation, Params, Method)). +protocol_error(Name, ExplanationFormat, Params) -> + protocol_error(Name, ExplanationFormat, Params, none). + +protocol_error(Name, ExplanationFormat, Params, Method) -> + exit(amqp_error(Name, ExplanationFormat, Params, Method)). not_found(R) -> protocol_error(not_found, "no ~s", [rs(R)]). diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 1f09ba33..cb59d7dc 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -565,18 +565,17 @@ handle_method0(MethodName, FieldsBin, State) -> MethodName, FieldsBin), State) catch exit:Reason -> - CompleteReason = - case Reason of - #amqp_error{method = none} -> - Reason#amqp_error{method = MethodName}; - _ -> - Reason - end, + CompleteReason = case Reason of + #amqp_error{method = none} -> + Reason#amqp_error{method = MethodName}; + OtherReason -> OtherReason + end, case State#v1.connection_state of running -> send_exception(State, 0, CompleteReason); Other -> throw({channel0_error, Other, CompleteReason}) end end. + handle_method0(#'connection.start_ok'{mechanism = Mechanism, response = Response}, State = #v1{connection_state = starting, @@ -792,21 +791,18 @@ map_exception(Channel, Reason) -> end, {ShouldClose, CloseChannel, CloseMethod}. -lookup_amqp_exception(#amqp_error{name = Name, - expl = Expl, - method = Method}) -> +lookup_amqp_exception( + #amqp_error{name = Name, expl = Expl, method = Method}) -> {ShouldClose, Code, Text} = rabbit_framing:lookup_amqp_exception(Name), ExplBin = list_to_binary(Expl), CompleteTextBin = <<Text/binary, " - ", ExplBin/binary>>, - SafeTextBin = - if - size(CompleteTextBin) > 255 -> - <<CompleteTextBin:252/binary, "...">>; - true -> - CompleteTextBin - end, - {ShouldClose, Code, SafeTextBin, Method}; - + SafeTextBin = if size(CompleteTextBin) > 255 -> + <<CompleteTextBin:252/binary, "...">>; + true -> CompleteTextBin + end, + {ShouldClose, Code, SafeTextBin, Method}; lookup_amqp_exception(Other) -> rabbit_log:warning("Non-AMQP exit reason '~p'~n", [Other]), - lookup_amqp_exception(#amqp_error{name = internal_error}). + {ShouldClose, Code, Text} = + rabbit_framing:lookup_amqp_exception(internal_error), + {ShouldClose, Code, Text, none}. |