Skip to content

Commit 137eb1c

Browse files
author
Simon MacMullen
committed
Wrap much less in try / catch
1 parent de12df8 commit 137eb1c

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

src/rabbit_channel.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,12 @@ binding_action(Fun, ExchangeNameBin, QueueNameBin, RoutingKey, Arguments,
909909
State),
910910
ExchangeName = rabbit_misc:r(VHostPath, exchange, ExchangeNameBin),
911911
check_read_permitted(ExchangeName, State),
912-
case catch Fun(ExchangeName, QueueName, ActualRoutingKey, Arguments,
912+
case Fun(ExchangeName, QueueName, ActualRoutingKey, Arguments,
913913
fun (_X, Q) ->
914-
rabbit_amqqueue:check_exclusive_access(Q, ReaderPid)
914+
try
915+
rabbit_amqqueue:check_exclusive_access(Q, ReaderPid)
916+
catch exit:Reason -> {error, Reason}
917+
end
915918
end) of
916919
{error, exchange_not_found} ->
917920
rabbit_misc:not_found(ExchangeName);

src/rabbit_exchange.erl

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -427,16 +427,19 @@ add_binding(ExchangeName, QueueName, RoutingKey, Arguments, InnerFun) ->
427427
%% this argument is used to check queue exclusivity;
428428
%% in general, we want to fail on that in preference to
429429
%% anything else
430-
InnerFun(X, Q),
431-
case mnesia:read({rabbit_route, B}) of
432-
[] ->
433-
sync_binding(B,
434-
X#exchange.durable andalso
435-
Q#amqqueue.durable,
436-
fun mnesia:write/3),
437-
{new, X, B};
438-
[_R] ->
439-
{existing, X, B}
430+
case InnerFun(X, Q) of
431+
{error, _} = E -> E;
432+
_ ->
433+
case mnesia:read({rabbit_route, B}) of
434+
[] ->
435+
sync_binding(B,
436+
X#exchange.durable andalso
437+
Q#amqqueue.durable,
438+
fun mnesia:write/3),
439+
{new, X, B};
440+
[_R] ->
441+
{existing, X, B}
442+
end
440443
end
441444
end) of
442445
{new, Exchange = #exchange{ type = Type }, Binding} ->
@@ -454,10 +457,15 @@ delete_binding(ExchangeName, QueueName, RoutingKey, Arguments, InnerFun) ->
454457
case mnesia:match_object(rabbit_route, #route{binding = B},
455458
write) of
456459
[] -> {error, binding_not_found};
457-
_ -> InnerFun(X, Q),
458-
ok = sync_binding(B, Q#amqqueue.durable,
459-
fun mnesia:delete_object/3),
460-
{maybe_auto_delete(X), B}
460+
_ ->
461+
case InnerFun(X, Q) of
462+
{error, _} = E -> E;
463+
_ ->
464+
ok =
465+
sync_binding(B, Q#amqqueue.durable,
466+
fun mnesia:delete_object/3),
467+
{maybe_auto_delete(X), B}
468+
end
461469
end
462470
end) of
463471
Err = {error, _} ->

0 commit comments

Comments
 (0)