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
diff --git a/lib/ocaml/src/TSocket.ml b/lib/ocaml/src/TSocket.ml
index c74864a..20c8613 100644
--- a/lib/ocaml/src/TSocket.ml
+++ b/lib/ocaml/src/TSocket.ml
@@ -11,8 +11,9 @@
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 @@
| 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