summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2009-05-20 21:09:08 +0100
committerMatthias Radestock <matthias@lshift.net>2009-05-20 21:09:08 +0100
commit48614ecb2defab39d393dcea9517cc68686d144a (patch)
tree94d81a756e3f4debcb5a219979ef5096caa70c97
parent69c22832851214c2c48afa782a64537b30e99717 (diff)
downloadrabbitmq-server-48614ecb2defab39d393dcea9517cc68686d144a.tar.gz
helper method for not_found errors
There was enough repetition to make it worthwhile
-rw-r--r--src/rabbit_amqqueue.erl4
-rw-r--r--src/rabbit_channel.erl9
-rw-r--r--src/rabbit_exchange.erl4
-rw-r--r--src/rabbit_misc.erl4
4 files changed, 9 insertions, 12 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl
index eb076e94..0316788f 100644
--- a/src/rabbit_amqqueue.erl
+++ b/src/rabbit_amqqueue.erl
@@ -201,9 +201,7 @@ with(Name, F, E) ->
with(Name, F) ->
with(Name, F, fun () -> {error, not_found} end).
with_or_die(Name, F) ->
- with(Name, F, fun () -> rabbit_misc:protocol_error(
- not_found, "no ~s", [rabbit_misc:rs(Name)])
- end).
+ with(Name, F, fun () -> rabbit_misc:not_found(Name) end).
list(VHostPath) ->
mnesia:dirty_match_object(
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index b2716ec4..e837c84f 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -579,8 +579,7 @@ handle_method(#'exchange.delete'{exchange = ExchangeNameBin,
check_configure_permitted(ExchangeName, State),
case rabbit_exchange:delete(ExchangeName, IfUnused) of
{error, not_found} ->
- rabbit_misc:protocol_error(
- not_found, "no ~s", [rabbit_misc:rs(ExchangeName)]);
+ rabbit_misc:not_found(ExchangeName);
{error, in_use} ->
die_precondition_failed(
"~s in use", [rabbit_misc:rs(ExchangeName)]);
@@ -746,11 +745,9 @@ binding_action(Fun, ExchangeNameBin, QueueNameBin, RoutingKey, Arguments,
check_read_permitted(ExchangeName, State),
case Fun(ExchangeName, QueueName, ActualRoutingKey, Arguments) of
{error, exchange_not_found} ->
- rabbit_misc:protocol_error(
- not_found, "no ~s", [rabbit_misc:rs(ExchangeName)]);
+ rabbit_misc:not_found(ExchangeName);
{error, queue_not_found} ->
- rabbit_misc:protocol_error(
- not_found, "no ~s", [rabbit_misc:rs(QueueName)]);
+ rabbit_misc:not_found(QueueName);
{error, exchange_and_queue_not_found} ->
rabbit_misc:protocol_error(
not_found, "no ~s and no ~s", [rabbit_misc:rs(ExchangeName),
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl
index fc89cfca..d6d70cba 100644
--- a/src/rabbit_exchange.erl
+++ b/src/rabbit_exchange.erl
@@ -164,9 +164,7 @@ lookup(Name) ->
lookup_or_die(Name) ->
case lookup(Name) of
{ok, X} -> X;
- {error, not_found} ->
- rabbit_misc:protocol_error(
- not_found, "no ~s", [rabbit_misc:rs(Name)])
+ {error, not_found} -> rabbit_misc:not_found(Name)
end.
list(VHostPath) ->
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index eced0b3c..7a395a6f 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -36,6 +36,7 @@
-export([method_record_type/1, polite_pause/0, polite_pause/1]).
-export([die/1, frame_error/2, protocol_error/3, protocol_error/4]).
+-export([not_found/1]).
-export([get_config/1, get_config/2, set_config/2]).
-export([dirty_read/1]).
-export([r/3, r/2, rs/1]).
@@ -72,6 +73,7 @@
(atom() | amqp_error(), string(), [any()]) -> no_return()).
-spec(protocol_error/4 ::
(atom() | amqp_error(), string(), [any()], atom()) -> no_return()).
+-spec(not_found/1 :: (r(atom())) -> no_return()).
-spec(get_config/1 :: (atom()) -> {'ok', any()} | not_found()).
-spec(get_config/2 :: (atom(), A) -> A).
-spec(set_config/2 :: (atom(), any()) -> 'ok').
@@ -139,6 +141,8 @@ protocol_error(Error, Explanation, Params, Method) ->
CompleteExplanation = lists:flatten(io_lib:format(Explanation, Params)),
exit({amqp, Error, CompleteExplanation, Method}).
+not_found(R) -> protocol_error(not_found, "no ~s", [rs(R)]).
+
get_config(Key) ->
case dirty_read({rabbit_config, Key}) of
{ok, {rabbit_config, Key, V}} -> {ok, V};