Skip to content

Commit 279c8ed

Browse files
committed
refactor: introduce rabbit_misc:protocol_error/1
so that the channel can get away with knowing a little bit less about error handling
1 parent 03ab566 commit 279c8ed

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/rabbit_channel.erl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,10 +928,8 @@ binding_action(Fun, ExchangeNameBin, QueueNameBin, RoutingKey, Arguments,
928928
not_found, "no binding ~s between ~s and ~s",
929929
[RoutingKey, rabbit_misc:rs(ExchangeName),
930930
rabbit_misc:rs(QueueName)]);
931-
%% When check_exclusive_access exits with a protocol error this gets
932-
%% wrapped by mnesia. Unwrap it and exit again.
933931
{error, #amqp_error{} = Error} ->
934-
exit(Error);
932+
rabbit_misc:protocol_error(Error);
935933
ok -> return_ok(State, NoWait, ReturnMethod)
936934
end.
937935

src/rabbit_misc.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
-export([method_record_type/1, polite_pause/0, polite_pause/1]).
3939
-export([die/1, frame_error/2, amqp_error/4,
40-
protocol_error/3, protocol_error/4]).
40+
protocol_error/3, protocol_error/4, protocol_error/1]).
4141
-export([not_found/1]).
4242
-export([get_config/1, get_config/2, set_config/2]).
4343
-export([dirty_read/1]).
@@ -95,6 +95,7 @@
9595
(rabbit_framing:amqp_exception(), string(), [any()],
9696
rabbit_framing:amqp_method_name())
9797
-> no_return()).
98+
-spec(protocol_error/1 :: (rabbit_types:amqp_error()) -> no_return()).
9899
-spec(not_found/1 :: (rabbit_types:r(atom())) -> no_return()).
99100
-spec(get_config/1 ::
100101
(atom()) -> rabbit_types:ok_or_error2(any(), 'not_found')).
@@ -199,7 +200,10 @@ protocol_error(Name, ExplanationFormat, Params) ->
199200
protocol_error(Name, ExplanationFormat, Params, none).
200201

201202
protocol_error(Name, ExplanationFormat, Params, Method) ->
202-
exit(amqp_error(Name, ExplanationFormat, Params, Method)).
203+
protocol_error(amqp_error(Name, ExplanationFormat, Params, Method)).
204+
205+
protocol_error(#amqp_error{} = Error) ->
206+
exit(Error).
203207

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

0 commit comments

Comments
 (0)