Skip to content

Commit 11a829e

Browse files
author
Matthias Radestock
committed
minor, mostly cosmetic, tweaks
1 parent d628253 commit 11a829e

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

include/rabbit.hrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
-record(ssl_socket, {tcp, ssl}).
6868
-record(delivery, {mandatory, immediate, txn, sender, message}).
6969

70-
-record(amqp_error, {name, expl = "", method = none}).
70+
-record(amqp_error, {name, expl, method = none}).
7171

7272
%%----------------------------------------------------------------------------
7373

src/rabbit_channel.erl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ handle_cast({method, Method, Content}, State) ->
127127
catch
128128
exit:Reason = #amqp_error{} ->
129129
ok = rollback_and_notify(State),
130-
CompleteReason = Reason#amqp_error{method =
131-
rabbit_misc:method_record_type(Method)},
132-
State#ch.reader_pid !
133-
{channel_exit, State#ch.channel, CompleteReason},
130+
MethodName = rabbit_misc:method_record_type(Method),
131+
State#ch.reader_pid ! {channel_exit, State#ch.channel,
132+
Reason#amqp_error{method = MethodName}},
134133
{stop, normal, State#ch{state = terminating}};
135134
exit:normal ->
136135
{stop, normal, State};

src/rabbit_misc.erl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
-include_lib("kernel/include/file.hrl").
3636

3737
-export([method_record_type/1, polite_pause/0, polite_pause/1]).
38-
-export([die/1, frame_error/2, amqp_error/4, protocol_error/3, protocol_error/4]).
38+
-export([die/1, frame_error/2, amqp_error/4,
39+
protocol_error/3, protocol_error/4]).
3940
-export([not_found/1]).
4041
-export([get_config/1, get_config/2, set_config/2]).
4142
-export([dirty_read/1]).
@@ -145,15 +146,15 @@ die(Error) ->
145146
frame_error(MethodName, BinaryFields) ->
146147
protocol_error(frame_error, "cannot decode ~w", [BinaryFields], MethodName).
147148

148-
amqp_error(Name, Explanation, Params, Method) ->
149-
#amqp_error{name = Name,
150-
expl = lists:flatten(io_lib:format(Explanation, Params)),
151-
method = Method}.
149+
amqp_error(Name, ExplanationFormat, Params, Method) ->
150+
Explanation = lists:flatten(io_lib:format(ExplanationFormat, Params)),
151+
#amqp_error{name = Name, expl = Explanation, method = Method}.
152152

153-
protocol_error(Name, Explanation, Params) ->
154-
protocol_error(Name, Explanation, Params, none).
155-
protocol_error(Name, Explanation, Params, Method) ->
156-
exit(amqp_error(Name, Explanation, Params, Method)).
153+
protocol_error(Name, ExplanationFormat, Params) ->
154+
protocol_error(Name, ExplanationFormat, Params, none).
155+
156+
protocol_error(Name, ExplanationFormat, Params, Method) ->
157+
exit(amqp_error(Name, ExplanationFormat, Params, Method)).
157158

158159
not_found(R) -> protocol_error(not_found, "no ~s", [rs(R)]).
159160

src/rabbit_reader.erl

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -565,18 +565,17 @@ handle_method0(MethodName, FieldsBin, State) ->
565565
MethodName, FieldsBin),
566566
State)
567567
catch exit:Reason ->
568-
CompleteReason =
569-
case Reason of
570-
#amqp_error{method = none} ->
571-
Reason#amqp_error{method = MethodName};
572-
_ ->
573-
Reason
574-
end,
568+
CompleteReason = case Reason of
569+
#amqp_error{method = none} ->
570+
Reason#amqp_error{method = MethodName};
571+
OtherReason -> OtherReason
572+
end,
575573
case State#v1.connection_state of
576574
running -> send_exception(State, 0, CompleteReason);
577575
Other -> throw({channel0_error, Other, CompleteReason})
578576
end
579577
end.
578+
580579
handle_method0(#'connection.start_ok'{mechanism = Mechanism,
581580
response = Response},
582581
State = #v1{connection_state = starting,
@@ -792,21 +791,18 @@ map_exception(Channel, Reason) ->
792791
end,
793792
{ShouldClose, CloseChannel, CloseMethod}.
794793

795-
lookup_amqp_exception(#amqp_error{name = Name,
796-
expl = Expl,
797-
method = Method}) ->
794+
lookup_amqp_exception(
795+
#amqp_error{name = Name, expl = Expl, method = Method}) ->
798796
{ShouldClose, Code, Text} = rabbit_framing:lookup_amqp_exception(Name),
799797
ExplBin = list_to_binary(Expl),
800798
CompleteTextBin = <<Text/binary, " - ", ExplBin/binary>>,
801-
SafeTextBin =
802-
if
803-
size(CompleteTextBin) > 255 ->
804-
<<CompleteTextBin:252/binary, "...">>;
805-
true ->
806-
CompleteTextBin
807-
end,
808-
{ShouldClose, Code, SafeTextBin, Method};
809-
799+
SafeTextBin = if size(CompleteTextBin) > 255 ->
800+
<<CompleteTextBin:252/binary, "...">>;
801+
true -> CompleteTextBin
802+
end,
803+
{ShouldClose, Code, SafeTextBin, Method};
810804
lookup_amqp_exception(Other) ->
811805
rabbit_log:warning("Non-AMQP exit reason '~p'~n", [Other]),
812-
lookup_amqp_exception(#amqp_error{name = internal_error}).
806+
{ShouldClose, Code, Text} =
807+
rabbit_framing:lookup_amqp_exception(internal_error),
808+
{ShouldClose, Code, Text, none}.

0 commit comments

Comments
 (0)