Skip to content

Commit 3120cdc

Browse files
author
Matthias Radestock
committed
helper method for not_found errors
There was enough repetition to make it worthwhile
1 parent d94afdb commit 3120cdc

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

src/rabbit_amqqueue.erl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ with(Name, F, E) ->
201201
with(Name, F) ->
202202
with(Name, F, fun () -> {error, not_found} end).
203203
with_or_die(Name, F) ->
204-
with(Name, F, fun () -> rabbit_misc:protocol_error(
205-
not_found, "no ~s", [rabbit_misc:rs(Name)])
206-
end).
204+
with(Name, F, fun () -> rabbit_misc:not_found(Name) end).
207205

208206
list(VHostPath) ->
209207
mnesia:dirty_match_object(

src/rabbit_channel.erl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ handle_method(#'exchange.delete'{exchange = ExchangeNameBin,
579579
check_configure_permitted(ExchangeName, State),
580580
case rabbit_exchange:delete(ExchangeName, IfUnused) of
581581
{error, not_found} ->
582-
rabbit_misc:protocol_error(
583-
not_found, "no ~s", [rabbit_misc:rs(ExchangeName)]);
582+
rabbit_misc:not_found(ExchangeName);
584583
{error, in_use} ->
585584
die_precondition_failed(
586585
"~s in use", [rabbit_misc:rs(ExchangeName)]);
@@ -746,11 +745,9 @@ binding_action(Fun, ExchangeNameBin, QueueNameBin, RoutingKey, Arguments,
746745
check_read_permitted(ExchangeName, State),
747746
case Fun(ExchangeName, QueueName, ActualRoutingKey, Arguments) of
748747
{error, exchange_not_found} ->
749-
rabbit_misc:protocol_error(
750-
not_found, "no ~s", [rabbit_misc:rs(ExchangeName)]);
748+
rabbit_misc:not_found(ExchangeName);
751749
{error, queue_not_found} ->
752-
rabbit_misc:protocol_error(
753-
not_found, "no ~s", [rabbit_misc:rs(QueueName)]);
750+
rabbit_misc:not_found(QueueName);
754751
{error, exchange_and_queue_not_found} ->
755752
rabbit_misc:protocol_error(
756753
not_found, "no ~s and no ~s", [rabbit_misc:rs(ExchangeName),

src/rabbit_exchange.erl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ lookup(Name) ->
164164
lookup_or_die(Name) ->
165165
case lookup(Name) of
166166
{ok, X} -> X;
167-
{error, not_found} ->
168-
rabbit_misc:protocol_error(
169-
not_found, "no ~s", [rabbit_misc:rs(Name)])
167+
{error, not_found} -> rabbit_misc:not_found(Name)
170168
end.
171169

172170
list(VHostPath) ->

src/rabbit_misc.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
-export([method_record_type/1, polite_pause/0, polite_pause/1]).
3838
-export([die/1, frame_error/2, protocol_error/3, protocol_error/4]).
39+
-export([not_found/1]).
3940
-export([get_config/1, get_config/2, set_config/2]).
4041
-export([dirty_read/1]).
4142
-export([r/3, r/2, rs/1]).
@@ -72,6 +73,7 @@
7273
(atom() | amqp_error(), string(), [any()]) -> no_return()).
7374
-spec(protocol_error/4 ::
7475
(atom() | amqp_error(), string(), [any()], atom()) -> no_return()).
76+
-spec(not_found/1 :: (r(atom())) -> no_return()).
7577
-spec(get_config/1 :: (atom()) -> {'ok', any()} | not_found()).
7678
-spec(get_config/2 :: (atom(), A) -> A).
7779
-spec(set_config/2 :: (atom(), any()) -> 'ok').
@@ -139,6 +141,8 @@ protocol_error(Error, Explanation, Params, Method) ->
139141
CompleteExplanation = lists:flatten(io_lib:format(Explanation, Params)),
140142
exit({amqp, Error, CompleteExplanation, Method}).
141143

144+
not_found(R) -> protocol_error(not_found, "no ~s", [rs(R)]).
145+
142146
get_config(Key) ->
143147
case dirty_read({rabbit_config, Key}) of
144148
{ok, {rabbit_config, Key, V}} -> {ok, V};

0 commit comments

Comments
 (0)