Browse Source

Raise update fun errors in calling process.

Roberto Ostinelli 3 years ago
parent
commit
e570f273f2
5 changed files with 24 additions and 8 deletions
  1. 4 2
      src/syn.erl
  2. 5 2
      src/syn_pg.erl
  3. 5 2
      src/syn_registry.erl
  4. 5 1
      test/syn_pg_SUITE.erl
  5. 5 1
      test/syn_registry_SUITE.erl

+ 4 - 2
src/syn.erl

@@ -288,9 +288,10 @@ register(Scope, Name, Pid, Meta) ->
 %% Possible error reasons:
 %% <ul>
 %% <li>`undefined': The Name cannot be found.</li>
-%% <li>`{update_fun, {Reason, Stacktrace}}': An error has occurred in applying the supplied Fun.</li>
 %% </ul>
 %%
+%% Note: an error in the update fun will be raised in the calling process.
+%%
 %% <h2>Examples</h2>
 %% <h3>Elixir</h3>
 %% ```
@@ -463,9 +464,10 @@ is_member(Scope, GroupName, Pid) ->
 %% Possible error reasons:
 %% <ul>
 %% <li>`undefined': The `pid()' cannot be found in GroupName.</li>
-%% <li>`{update_fun, {Reason, Stacktrace}}': An error has occurred in applying the supplied Fun.</li>
 %% </ul>
 %%
+%% Note: an error in the update fun will be raised in the calling process.
+%%
 %% <h2>Examples</h2>
 %% <h3>Elixir</h3>
 %% ```

+ 5 - 2
src/syn_pg.erl

@@ -181,7 +181,10 @@ join_or_update(Scope, GroupName, Pid, MetaOrFun) ->
                     {ok, {Pid, Meta}};
 
                 {{error, Reason}, _} ->
-                    {error, Reason}
+                    {error, Reason};
+
+                {raise, Class, Reason, Stacktrace} ->
+                    erlang:raise(Class, Reason, Stacktrace)
             end
     end.
 
@@ -339,7 +342,7 @@ handle_call({'3.0', join_or_update_on_node, RequesterNode, GroupName, Pid, MetaO
                             "SYN[~s] Error ~p:~p in pg update function: ~p",
                             [node(), Class, Reason, Stacktrace]
                         ),
-                        {reply, {{error, {update_fun, {Reason, Stacktrace}}}, undefined}, State}
+                        {reply, {raise, Class, Reason, Stacktrace}, State}
                     end;
 
                 {{_, _}, MetaOrFun, _, _, _} ->

+ 5 - 2
src/syn_registry.erl

@@ -132,7 +132,10 @@ register_or_update(Scope, Name, Pid, MetaOrFun) ->
                     {ok, {Pid, Meta}};
 
                 {{error, Reason}, _} ->
-                    {error, Reason}
+                    {error, Reason};
+
+                {raise, Class, Reason, Stacktrace} ->
+                    erlang:raise(Class, Reason, Stacktrace)
             end
     end.
 
@@ -249,7 +252,7 @@ handle_call({'3.0', register_or_update_on_node, RequesterNode, Name, Pid, MetaOr
                             "SYN[~s] Error ~p:~p in registry update function: ~p",
                             [node(), Class, Reason, Stacktrace]
                         ),
-                        {reply, {{error, {update_fun, {Reason, Stacktrace}}}, undefined}, State}
+                        {reply, {raise, Class, Reason, Stacktrace}, State}
                     end;
 
                 {Name, Pid, MetaOrFun, _, _, _} ->

+ 5 - 1
test/syn_pg_SUITE.erl

@@ -1692,7 +1692,11 @@ three_nodes_member_and_update(Config) ->
     {error, undefined} = syn:update_member(scope_all, "my-group", PidOn1, fun(ExistingMeta) -> ExistingMeta end),
     InvalidPid = list_to_pid("<0.9999.0>"),
     {error, not_alive} = syn:update_member(scope_all, "my-group", InvalidPid, fun(ExistingMeta) -> ExistingMeta end),
-    {error, {update_fun, {badarith, _}}} = syn:update_member(scope_all, "my-group", Pid, fun(_ExistingMeta) -> 1/0 end),
+
+    %% throw in calling process
+    {'EXIT', {test_error, _Stacktrace}} = (catch syn:update_member(scope_all, "my-group", Pid, fun(_ExistingMeta) ->
+        error(test_error)
+    end)),
 
     %% update
     {ok, {Pid, {recipient, TestPid, 20}}} = syn:update_member(scope_all, "my-group", Pid, fun({recipient, TestPid0, Count}) ->

+ 5 - 1
test/syn_registry_SUITE.erl

@@ -1538,7 +1538,11 @@ three_nodes_update(Config) ->
 
     %% errors
     {error, undefined} = syn:update_registry(scope_all, "unknown", fun(_IPid, ExistingMeta) -> ExistingMeta end),
-    {error, {update_fun, {badarith, _}}} = syn:update_registry(scope_all, "my-proc", fun(_IPid, _IMeta) -> 1/0 end),
+
+    %% throw in calling process
+    {'EXIT', {test_error, _Stacktrace}} = (catch syn:update_registry(scope_all, "my-proc", fun(_IPid, _IMeta) ->
+        error(test_error)
+    end)),
 
     %% retrieve
     syn_test_suite_helper:assert_wait(