Permalink
Browse files

Return errors to caller instead of crashing

  • Loading branch information...
1 parent c75e333 commit d49dd0ce3832cd79e131204d67d8f4bee2fde90c @msantos committed Sep 13, 2012
Showing with 14 additions and 6 deletions.
  1. +7 −3 src/verx_client_tcp.erl
  2. +7 −3 src/verx_client_tls.erl
@@ -69,8 +69,10 @@
call(Ref, Proc) ->
call(Ref, Proc, []).
call(Ref, Proc, Arg) when is_pid(Ref), is_atom(Proc), is_list(Arg) ->
- {ok, Serial} = cast(Ref, Proc, Arg, infinity),
- reply(Ref, Serial).
+ case cast(Ref, Proc, Arg, infinity) of
+ {ok, Serial} -> reply(Ref, Serial);
+ Error -> Error
+ end.
cast(Ref, Proc) ->
cast(Ref, Proc, [], infinity).
@@ -83,7 +85,9 @@ reply(Ref, Serial) ->
reply(Ref, Serial, infinity).
reply(Ref, Serial, Timeout) ->
receive
- {verx, Ref, {#remote_message_header{serial = <<Serial:32>>, type = <<?REMOTE_REPLY:32>>}, _} = Reply} ->
+ {verx, Ref, {#remote_message_header{
+ serial = <<Serial:32>>,
+ type = <<?REMOTE_REPLY:32>>}, _} = Reply} ->
verx_rpc:status(Reply)
after
Timeout ->
@@ -69,8 +69,10 @@
call(Ref, Proc) ->
call(Ref, Proc, []).
call(Ref, Proc, Arg) when is_pid(Ref), is_atom(Proc), is_list(Arg) ->
- {ok, Serial} = cast(Ref, Proc, Arg, infinity),
- reply(Ref, Serial).
+ case cast(Ref, Proc, Arg, infinity) of
+ {ok, Serial} -> reply(Ref, Serial);
+ Error -> Error
+ end.
cast(Ref, Proc) ->
cast(Ref, Proc, [], infinity).
@@ -83,7 +85,9 @@ reply(Ref, Serial) ->
reply(Ref, Serial, infinity).
reply(Ref, Serial, Timeout) ->
receive
- {verx, Ref, {#remote_message_header{serial = <<Serial:32>>, type = <<?REMOTE_REPLY:32>>}, _} = Reply} ->
+ {verx, Ref, {#remote_message_header{
+ serial = <<Serial:32>>,
+ type = <<?REMOTE_REPLY:32>>}, _} = Reply} ->
verx_rpc:status(Reply)
after
Timeout ->

0 comments on commit d49dd0c

Please sign in to comment.