Permalink
Browse files

more helpful exceptions, applied to gproc_dist

  • Loading branch information...
1 parent d9314f3 commit 203e5deaa1619670c160e5a467f7acdf2cac816c @uwiger uwiger committed with Jan 11, 2012
Showing with 13 additions and 12 deletions.
  1. +13 −12 src/gproc_dist.erl
View
@@ -53,6 +53,7 @@
code_change/4,
terminate/2]).
+-include("gproc_int.hrl").
-include("gproc.hrl").
-define(SERVER, ?MODULE).
@@ -98,45 +99,45 @@ reg({_,g,_} = Key, Value) ->
%% anything global
leader_call({reg, Key, Value, self()});
reg(_, _) ->
- erlang:error(badarg).
+ ?THROW(badarg).
reg_shared({_,g,_} = Key, Value) ->
leader_call({reg, Key, Value, shared});
reg_shared(_, _) ->
- erlang:error(badarg).
+ ?THROW(badarg).
mreg(T, KVL) ->
if is_list(KVL) -> leader_call({mreg, T, g, KVL, self()});
- true -> erlang:error(badarg)
+ true -> ?THROW(badarg)
end.
munreg(T, Keys) ->
if is_list(Keys) -> leader_call({munreg, T, g, Keys, self()});
- true -> erlang:error(badarg)
+ true -> ?THROW(badarg)
end.
unreg({_,g,_} = Key) ->
leader_call({unreg, Key, self()});
unreg(_) ->
- erlang:error(badarg).
+ ?THROW(badarg).
unreg_shared({T,g,_} = Key) when T==c; T==a ->
leader_call({unreg, Key, shared});
unreg_shared(_) ->
- erlang:error(badarg).
+ ?THROW(badarg).
set_value({T,g,_} = Key, Value) when T==a; T==c ->
if is_integer(Value) ->
leader_call({set, Key, Value});
true ->
- erlang:error(badarg)
+ ?THROW(badarg)
end;
set_value({_,g,_} = Key, Value) ->
leader_call({set, Key, Value, self()});
set_value(_, _) ->
- erlang:error(badarg).
+ ?THROW(badarg).
give_away({_,g,_} = Key, To) ->
leader_call({give_away, Key, To, self()}).
@@ -145,18 +146,18 @@ give_away({_,g,_} = Key, To) ->
update_counter({c,g,_} = Key, Incr) when is_integer(Incr) ->
leader_call({update_counter, Key, Incr, self()});
update_counter(_, _) ->
- erlang:error(badarg).
+ ?THROW(badarg).
update_shared_counter({c,g,_} = Key, Incr) when is_integer(Incr) ->
leader_call({update_counter, Key, Incr, shared});
update_shared_counter(_, _) ->
- erlang:error(badarg).
+ ?THROW(badarg).
reset_counter({c,g,_} = Key) ->
leader_call({reset_counter, Key, self()});
reset_counter(_) ->
- erlang:error(badarg).
+ ?THROW(badarg).
%% @spec sync() -> true
@@ -578,7 +579,7 @@ ets_key(K, Pid) ->
leader_call(Req) ->
case gen_leader:leader_call(?MODULE, Req) of
- badarg -> erlang:error(badarg, Req);
+ badarg -> ?THROW(badarg);
Reply -> Reply
end.

0 comments on commit 203e5de

Please sign in to comment.