Skip to content

Handle more failure types in the rabbitmqqueue:declare/6 when declaring a stream (backport #11742) #11777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions deps/rabbit/src/rabbit_amqp_management.erl
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ handle_http_req(HttpMethod = <<"PUT">>,
Result;
{error, not_found} ->
PermCache2 = check_dead_letter_exchange(QName, QArgs, User, PermCache1),
case rabbit_amqqueue:declare(
QName, Durable, AutoDelete, QArgs, Owner, Username) of
try rabbit_amqqueue:declare(
QName, Durable, AutoDelete, QArgs, Owner, Username) of
{new, Q} ->
rabbit_core_metrics:queue_created(QName),
{Q, 0, 0, <<"201">>, PermCache2};
Expand All @@ -169,6 +169,11 @@ handle_http_req(HttpMethod = <<"PUT">>,
ReasonArgs);
{protocol_error, _ErrorType, Reason, ReasonArgs} ->
throw(<<"400">>, Reason, ReasonArgs)
catch exit:#amqp_error{name = precondition_failed,
explanation = Expl} ->
throw(<<"409">>, Expl, []);
exit:#amqp_error{explanation = Expl} ->
throw(<<"400">>, Expl, [])
end;
{error, {absent, Q, Reason}} ->
absent(Q, Reason)
Expand Down
15 changes: 15 additions & 0 deletions deps/rabbitmq_amqp_client/test/management_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ groups() ->
declare_queue_inequivalent_fields,
declare_queue_inequivalent_exclusive,
declare_queue_invalid_field,
declare_queue_invalid_arg,
declare_default_exchange,
declare_exchange_amq_prefix,
declare_exchange_line_feed,
Expand Down Expand Up @@ -528,6 +529,20 @@ declare_queue_invalid_field(Config) ->
amqp10_msg:body(Resp)),
ok = cleanup(Init).

declare_queue_invalid_arg(Config) ->
Init = {_, LinkPair} = init(Config),
QName = <<"👌"/utf8>>,
QProps = #{arguments => #{<<"x-queue-type">> => {utf8, <<"stream">>},
<<"x-dead-letter-exchange">> => {utf8, <<"dlx is invalid for stream">>}}},
{error, Resp} = rabbitmq_amqp_client:declare_queue(LinkPair, QName, QProps),
?assertMatch(#{subject := <<"409">>}, amqp10_msg:properties(Resp)),
?assertEqual(
#'v1_0.amqp_value'{
content = {utf8, <<"invalid arg 'x-dead-letter-exchange' for queue '", QName/binary,
"' in vhost '/' of queue type rabbit_stream_queue">>}},
amqp10_msg:body(Resp)),
ok = cleanup(Init).

declare_default_exchange(Config) ->
Init = {_, LinkPair} = init(Config),
{error, Resp} = rabbitmq_amqp_client:declare_exchange(LinkPair, ?DEFAULT_EXCHANGE, #{}),
Expand Down
Loading