Skip to content

Commit 8d4e9e4

Browse files
author
Marek Majkowski
committed
Merged bug 20399 into default.
2 parents b35f6b0 + a69f8c8 commit 8d4e9e4

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/rabbit_channel.erl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,6 @@ expand_routing_key_shortcut(<<>>, <<>>,
260260
expand_routing_key_shortcut(_QueueNameBin, RoutingKey, _State) ->
261261
RoutingKey.
262262

263-
die_precondition_failed(Fmt, Params) ->
264-
%% FIXME: 406 should be replaced with precondition_failed when we
265-
%% move to AMQP spec >=8.1
266-
rabbit_misc:protocol_error({false, 406, <<"PRECONDITION_FAILED">>},
267-
Fmt, Params).
268-
269263
%% check that an exchange/queue name does not contain the reserved
270264
%% "amq." prefix.
271265
%%
@@ -610,8 +604,8 @@ handle_method(#'exchange.delete'{exchange = ExchangeNameBin,
610604
{error, not_found} ->
611605
rabbit_misc:not_found(ExchangeName);
612606
{error, in_use} ->
613-
die_precondition_failed(
614-
"~s in use", [rabbit_misc:rs(ExchangeName)]);
607+
rabbit_misc:protocol_error(
608+
precondition_failed, "~s in use", [rabbit_misc:rs(ExchangeName)]);
615609
ok ->
616610
return_ok(State, NoWait, #'exchange.delete_ok'{})
617611
end;
@@ -685,11 +679,11 @@ handle_method(#'queue.delete'{queue = QueueNameBin,
685679
QueueName,
686680
fun (Q) -> rabbit_amqqueue:delete(Q, IfUnused, IfEmpty) end) of
687681
{error, in_use} ->
688-
die_precondition_failed(
689-
"~s in use", [rabbit_misc:rs(QueueName)]);
682+
rabbit_misc:protocol_error(
683+
precondition_failed, "~s in use", [rabbit_misc:rs(QueueName)]);
690684
{error, not_empty} ->
691-
die_precondition_failed(
692-
"~s not empty", [rabbit_misc:rs(QueueName)]);
685+
rabbit_misc:protocol_error(
686+
precondition_failed, "~s not empty", [rabbit_misc:rs(QueueName)]);
693687
{ok, PurgedMessageCount} ->
694688
return_ok(State, NoWait,
695689
#'queue.delete_ok'{

src/rabbit_reader.erl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -751,18 +751,27 @@ map_exception(Channel, Reason) ->
751751
end,
752752
{ShouldClose, CloseChannel, CloseMethod}.
753753

754-
lookup_amqp_exception(
755-
#amqp_error{name = Name, explanation = Expl, method = Method}) ->
754+
%% FIXME: this clause can go when we move to AMQP spec >=8.1
755+
lookup_amqp_exception(#amqp_error{name = precondition_failed,
756+
explanation = Expl,
757+
method = Method}) ->
758+
ExplBin = amqp_exception_explanation(<<"PRECONDITION_FAILED">>, Expl),
759+
{false, 406, ExplBin, Method};
760+
lookup_amqp_exception(#amqp_error{name = Name,
761+
explanation = Expl,
762+
method = Method}) ->
756763
{ShouldClose, Code, Text} = rabbit_framing:lookup_amqp_exception(Name),
757-
ExplBin = list_to_binary(Expl),
758-
CompleteTextBin = <<Text/binary, " - ", ExplBin/binary>>,
759-
SafeTextBin = if size(CompleteTextBin) > 255 ->
760-
<<CompleteTextBin:252/binary, "...">>;
761-
true -> CompleteTextBin
762-
end,
763-
{ShouldClose, Code, SafeTextBin, Method};
764+
ExplBin = amqp_exception_explanation(Text, Expl),
765+
{ShouldClose, Code, ExplBin, Method};
764766
lookup_amqp_exception(Other) ->
765767
rabbit_log:warning("Non-AMQP exit reason '~p'~n", [Other]),
766768
{ShouldClose, Code, Text} =
767769
rabbit_framing:lookup_amqp_exception(internal_error),
768770
{ShouldClose, Code, Text, none}.
771+
772+
amqp_exception_explanation(Text, Expl) ->
773+
ExplBin = list_to_binary(Expl),
774+
CompleteTextBin = <<Text/binary, " - ", ExplBin/binary>>,
775+
if size(CompleteTextBin) > 255 -> <<CompleteTextBin:252/binary, "...">>;
776+
true -> CompleteTextBin
777+
end.

0 commit comments

Comments
 (0)