Hi There,

I'm using Thrift's Erlang bindings. My code that uses thrift_client wants to be able to handle errors, such as a failed connection attempt, but rather than receiving an error code or exception I'm getting the following crash:

** Reason for termination ==
** {{badmatch,{error,econnrefused}},
    [{thrift_binary_protocol,'-new_protocol_factory/2-fun-0-',2},
     {thrift_client,handle_call,3},
     {gen_server,handle_msg,5},
     {proc_lib,init_p,5}]}

I modified thrift_client.erl and thrift_binary_protocol.erl to pass on errors to the callers, which solves the problem for me. The diffs for these files are shown below.

Has anyone else experienced this problem? Is the solution appropriate (I've only been at Erlang for less than a year), and if so, can it be incorporated into the repository, or would that change how existing applications expect it to behave?

Thanks!

Mike Beam



Index: thrift_client.erl
===================================================================
--- thrift_client.erl   (revision 711771)
+++ thrift_client.erl   (working copy)
@@ -61,15 +61,20 @@
   when is_integer(Port), is_atom(Service), is_list(Options) ->
     {ProtoOpts, TransOpts} = split_options(Options),

-    {ok, TransportFactory} =
- thrift_socket_transport:new_transport_factory(Host, Port, TransOpts), + case thrift_socket_transport:new_transport_factory(Host, Port, TransOpts) of
+        {ok, TransportFactory} ->
+ case thrift_binary_protocol:new_protocol_factory(TransportFactory, ProtoOpts) of
+                {ok, ProtocolFactory} ->
+                    start_link(ProtocolFactory, Service);
+
+                Else -> Else
+            end;
+
+        Else -> Else
+    end.
+

- {ok, ProtocolFactory} = thrift_binary_protocol:new_protocol_factory(
-                              TransportFactory, ProtoOpts),

-    start_link(ProtocolFactory, Service).
-
-
 %% ProtocolFactory :: fun() -> thrift_protocol()
 start_link(ProtocolFactory, Service)
   when is_function(ProtocolFactory), is_atom(Service) ->
Index: thrift_binary_protocol.erl
===================================================================
--- thrift_binary_protocol.erl  (revision 711771)
+++ thrift_binary_protocol.erl  (working copy)
@@ -301,11 +301,15 @@
 new_protocol_factory(TransportFactory, Options) ->
     ParsedOpts = parse_factory_options(Options, #tbp_opts{}),
     F = fun() ->
-                {ok, Transport} = TransportFactory(),
-                thrift_binary_protocol:new(
-                  Transport,
-                  [{strict_read,  ParsedOpts#tbp_opts.strict_read},
-                   {strict_write, ParsedOpts#tbp_opts.strict_write}])
+                case TransportFactory() of
+                    {ok, Transport} ->
+                        thrift_binary_protocol:new(
+                          Transport,
+ [{strict_read, ParsedOpts#tbp_opts.strict_read}, + {strict_write, ParsedOpts#tbp_opts.strict_write}]);
+
+                    Else -> Else
+                end
         end,
     {ok, F}.

Reply via email to