summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2012-04-05 11:45:37 +0100
committerSimon MacMullen <simon@rabbitmq.com>2012-04-05 11:45:37 +0100
commit1c69dae9fc7a122e3b0471afd5a95bfd37517762 (patch)
treee3be2761e382fe49d96f3dd8f87e7a2dff6ab9f3 /src
parent0c9e2fa891b44901dd89593d92840f526258dd07 (diff)
downloadrabbitmq-server-git-1c69dae9fc7a122e3b0471afd5a95bfd37517762.tar.gz
Base validation on returning error tuples rather than existing; thus report all errors (for a given pass) rather than the first error we see.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_misc.erl7
-rw-r--r--src/rabbit_nodes.erl3
-rw-r--r--src/rabbit_runtime_parameters.erl74
3 files changed, 58 insertions, 26 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index 3b7e0b41c4..65fbdc8ed1 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -40,7 +40,8 @@
-export([upmap/2, map_in_order/2]).
-export([table_filter/3]).
-export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]).
--export([format/2, format_stderr/2, with_local_io/1, local_info_msg/2]).
+-export([format/2, format_many/1, format_stderr/2]).
+-export([with_local_io/1, local_info_msg/2]).
-export([start_applications/1, stop_applications/1]).
-export([unfold/2, ceil/1, queue_fold/3]).
-export([sort_field_table/1]).
@@ -157,6 +158,7 @@
-> 'ok' | 'aborted').
-spec(dirty_dump_log/1 :: (file:filename()) -> ok_or_error()).
-spec(format/2 :: (string(), [any()]) -> string()).
+-spec(format_many/1 :: ([{string(), [any()]}]) -> string()).
-spec(format_stderr/2 :: (string(), [any()]) -> 'ok').
-spec(with_local_io/1 :: (fun (() -> A)) -> A).
-spec(local_info_msg/2 :: (string(), [any()]) -> 'ok').
@@ -550,6 +552,9 @@ dirty_dump_log1(LH, {K, Terms, BadBytes}) ->
format(Fmt, Args) -> lists:flatten(io_lib:format(Fmt, Args)).
+format_many(List) ->
+ lists:flatten([io_lib:format(F ++ "~n", A) || {F, A} <- List]).
+
format_stderr(Fmt, Args) ->
case os:type() of
{unix, _} ->
diff --git a/src/rabbit_nodes.erl b/src/rabbit_nodes.erl
index 9a972d9e78..28ba469863 100644
--- a/src/rabbit_nodes.erl
+++ b/src/rabbit_nodes.erl
@@ -56,8 +56,7 @@ diagnostics(Nodes) ->
"hosts, their running nodes and ports:", [Nodes]}] ++
[diagnostics_host(Host) || Host <- Hosts] ++
diagnostics0(),
- lists:flatten([io_lib:format(F ++ "~n", A) || NodeDiag <- NodeDiags,
- {F, A} <- [NodeDiag]]).
+ rabbit_misc:format_many(lists:flatten(NodeDiags)).
diagnostics0() ->
[{"~ncurrent node details:~n- node name: ~w", [node()]},
diff --git a/src/rabbit_runtime_parameters.erl b/src/rabbit_runtime_parameters.erl
index 81c0cb64a8..77dbc5eb6b 100644
--- a/src/rabbit_runtime_parameters.erl
+++ b/src/rabbit_runtime_parameters.erl
@@ -28,24 +28,45 @@
%%---------------------------------------------------------------------------
set(AppName, Key, Term) ->
- Module = lookup_app(AppName),
- validate(Term),
- Module:validate(AppName, Key, Term),
+ case set0(AppName, Key, Term) of
+ ok -> ok;
+ {errors, L} -> {error_string, rabbit_misc:format_many(
+ [{"Validation failed~n", []} | L])}
+ end.
+
+set0(AppName, Key, Term) ->
+ case lookup_app(AppName) of
+ {ok, Module} -> case flatten_errors(validate(Term)) of
+ ok -> case flatten_errors(
+ Module:validate(AppName, Key, Term)) of
+ ok -> update(AppName, Key, Term),
+ Module:notify(AppName, Key, Term),
+ ok;
+ E -> E
+ end;
+ E -> E
+ end;
+ E -> E
+ end.
+
+update(AppName, Key, Term) ->
ok = rabbit_misc:execute_mnesia_transaction(
fun () ->
ok = mnesia:write(?TABLE, c(AppName, Key, Term), write)
- end),
- Module:notify(AppName, Key, Term),
- ok.
+ end).
clear(AppName, Key) ->
- Module = lookup_app(AppName),
- ok = rabbit_misc:execute_mnesia_transaction(
- fun () ->
- ok = mnesia:delete(?TABLE, {AppName, Key}, write)
- end),
- Module:notify_clear(AppName, Key),
- ok.
+ case lookup_app(AppName) of
+ {ok, Module} ->
+ ok = rabbit_misc:execute_mnesia_transaction(
+ fun () ->
+ ok = mnesia:delete(?TABLE, {AppName, Key}, write)
+ end),
+ Module:notify_clear(AppName, Key),
+ ok;
+ E ->
+ E
+ end.
list() ->
[p(P) || P <- rabbit_misc:dirty_read_all(?TABLE)].
@@ -105,8 +126,8 @@ info_keys() -> [app_name, key, value].
lookup_app(App) ->
case rabbit_registry:lookup_module(
runtime_parameter, list_to_atom(binary_to_list(App))) of
- {error, not_found} -> exit({application_not_found, App});
- {ok, Module} -> Module
+ {error, not_found} -> {errors, [{"application ~s not found", [App]}]};
+ {ok, Module} -> {ok, Module}
end.
parse(Src0) ->
@@ -137,17 +158,24 @@ format(Term) ->
%% We will want to be able to biject these to JSON. So we have some
%% generic restrictions on what we consider acceptable.
validate(Proplist = [T | _]) when is_tuple(T) -> validate_proplist(Proplist);
-validate(L) when is_list(L) -> [validate(I) || I <- L];
-validate(T) when is_tuple(T) -> exit({tuple, T});
+validate(L) when is_list(L) -> validate_list(L);
+validate(T) when is_tuple(T) -> {error, "tuple: ~p", [T]};
validate(true) -> ok;
validate(false) -> ok;
validate(null) -> ok;
-validate(A) when is_atom(A) -> exit({non_bool_atom, A});
+validate(A) when is_atom(A) -> {error, "atom: ~p", [A]};
validate(N) when is_number(N) -> ok;
validate(B) when is_binary(B) -> ok.
-validate_proplist([]) -> ok;
-validate_proplist([{K, V} | Rest]) when is_binary(K) -> validate(V),
- validate_proplist(Rest);
-validate_proplist([{K, _V} | _Rest]) -> exit({bad_key, K});
-validate_proplist([H | _Rest]) -> exit({not_two_tuple,H}).
+validate_list(L) -> [validate(I) || I <- L].
+validate_proplist(L) -> [vp(I) || I <- L].
+
+vp({K, V}) when is_binary(K) -> validate(V);
+vp({K, _V}) -> {error, "bad key: ~p", [K]};
+vp(H) -> {error, "not two tuple: ~p", [H]}.
+
+flatten_errors(L) ->
+ case [{F, A} || I <- lists:flatten(L), {error, F, A} <- [I]] of
+ [] -> ok;
+ E -> {errors, E}
+ end.