From 94112d699411fcca2bde9721da46ddcd4c15a5bf Mon Sep 17 00:00:00 2001 From: iproctor Date: Fri, 17 Aug 2007 21:34:15 +0000 Subject: [PATCH] Thrift: OCaml TSocket more helpful exceptions Summary: On unix error it tells you the cause. Reviewed by: mcslee Test plan: Had some unix errors, read the messages. Revert plan: yes git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665208 13f79535-47bb-0310-9956-ffa450edef68 --- lib/ocaml/src/TSocket.ml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ocaml/src/TSocket.ml b/lib/ocaml/src/TSocket.ml index c74864a9..20c86132 100644 --- a/lib/ocaml/src/TSocket.ml +++ b/lib/ocaml/src/TSocket.ml @@ -11,8 +11,9 @@ object (self) try let addr = (let {Unix.h_addr_list=x} = Unix.gethostbyname host in x.(0)) in chans <- Some(Unix.open_connection (Unix.ADDR_INET (addr,port))) - with _ -> - raise (T.E (T.NOT_OPEN, ("TSocket: Could not connect to "^host^":"^(string_of_int port)))) + with + Unix.Unix_error (e,fn,_) -> raise (T.E (T.NOT_OPEN, ("TSocket: Could not connect to "^host^":"^(string_of_int port)^" because: "^fn^":"^(Unix.error_message e)))) + | _ -> raise (T.E (T.NOT_OPEN, ("TSocket: Could not connect to "^host^":"^(string_of_int port)))) method close = match chans with @@ -25,7 +26,9 @@ object (self) | Some(i,o) -> try really_input i buf off len; len - with _ -> raise (T.E (T.UNKNOWN, ("TSocket: Could not read "^(string_of_int len)^" from "^host^":"^(string_of_int port)))) + with + Unix.Unix_error (e,fn,_) -> raise (T.E (T.UNKNOWN, ("TSocket: Could not read "^(string_of_int len)^" from "^host^":"^(string_of_int port)^" because: "^fn^":"^(Unix.error_message e)))) + | _ -> raise (T.E (T.UNKNOWN, ("TSocket: Could not read "^(string_of_int len)^" from "^host^":"^(string_of_int port)))) method write buf off len = match chans with None -> raise (T.E (T.NOT_OPEN, "TSocket: Socket not open")) | Some(i,o) -> output o buf off len -- 2.17.1