From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 9B5437EE6B for ; Fri, 29 Nov 2013 15:35:00 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of ollie.frolovs.2012@my.bristol.ac.uk) identity=pra; client-ip=74.125.82.181; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ollie.frolovs.2012@my.bristol.ac.uk"; x-sender="ollie.frolovs.2012@my.bristol.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of ollie.frolovs.2012@my.bristol.ac.uk) identity=mailfrom; client-ip=74.125.82.181; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ollie.frolovs.2012@my.bristol.ac.uk"; x-sender="ollie.frolovs.2012@my.bristol.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-we0-f181.google.com) identity=helo; client-ip=74.125.82.181; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ollie.frolovs.2012@my.bristol.ac.uk"; x-sender="postmaster@mail-we0-f181.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoYCAPekmFJKfVK1lGdsb2JhbABZgz+mYpNsFg4BAQEBBwsLCRIqglMlW1gPAQUBIogQBAQBoFWDBZBnhE+HQpIvgRMDnlmJYUGEVQ X-IPAS-Result: AoYCAPekmFJKfVK1lGdsb2JhbABZgz+mYpNsFg4BAQEBBwsLCRIqglMlW1gPAQUBIogQBAQBoFWDBZBnhE+HQpIvgRMDnlmJYUGEVQ X-IronPort-AV: E=Sophos;i="4.93,798,1378850400"; d="scan'208";a="38550028" Received: from mail-we0-f181.google.com ([74.125.82.181]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 29 Nov 2013 15:35:00 +0100 Received: by mail-we0-f181.google.com with SMTP id x55so9335299wes.40 for ; Fri, 29 Nov 2013 06:34:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:content-type:content-transfer-encoding :subject:message-id:date:to:mime-version; bh=AFwbV1NIrnSnBe7o86zswCyTMDT+P4jo1e3JiASZUKA=; b=HBNW34iErj0t1Waf52QbTqLiINpaptxtAzVXOZ0+HZwL11jaGZIGUstTLwdRcxY1Io CKG8WNog6+LSzRCxV3GGS6lHzUFbKxuOnqeLgt2qtMTxsY0/HFIebs53R8IVqecL0I4l 0ujdU+wAl9cyCfBYw2PW+AFauW6K7PbVCUVn0khLS8f8U0/h/Dcp+ei1A3CmHLBW7+3g pTgILer5oCpeDcSqAseBIIRbPCMxuaYfBE/IAXGKcwdbY+WErtAqax2UIIer4FrTCOMY Et4bVC4vSozqk34nvuolBfe/xta6oOOvrCQFprf8PrJxrc2r/hAtSQO4/T527JuJWaLU I/sg== X-Gm-Message-State: ALoCoQml/LTPe+mVdFKIgFmt/yHvdoz1T+XyA1rygUNlFpe5MVwkiw8sws6GjsSpwHG19k7M1ZeL X-Received: by 10.180.79.227 with SMTP id m3mr7293927wix.2.1385735699640; Fri, 29 Nov 2013 06:34:59 -0800 (PST) Received: from [10.0.0.92] (94.197.120.197.threembb.co.uk. [94.197.120.197]) by mx.google.com with ESMTPSA id bk7sm10042371wib.10.2013.11.29.06.34.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 06:34:59 -0800 (PST) From: Ollie Frolovs Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Message-Id: <96620953-9991-4976-A207-7DBB32584D57@my.bristol.ac.uk> Date: Fri, 29 Nov 2013 14:34:40 +0000 To: caml users Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1822\)) X-Mailer: Apple Mail (2.1822) X-Validation-by: ollie.frolovs.2012@my.bristol.ac.uk Subject: [Caml-list] Extracting exception details (Async, Cohttp, Exn) Hello list! I=92m designing a function to query a web service and i am stuck trying to = implement quality error handling/reporting. I have a specific question =96 = how do i extract the =93description=94 field from the Core=92s Exn type? I=92ve been experimenting in the top-level and i got stuck. My workflow wit= h step by step explanations is below. First, i create a request, which i believe does not run just yet because it= is =93deferred=94. utop # let result =3D try_with (fun () -> Cohttp_async.Client.get (Uri.of_s= tring "http://127.0.0.2"));; val result : (Cohttp.Response.t * string Pipe.Reader.t, exn) Result.t Defer= red.t =3D Then, i =93Deferred.map" the result at which point the Cohttp/Async library= try to connect and (as desired) fail.=20 I=92m using ident here because i want to see what=92s inside the exception,= thankfully the pretty-printer for exceptions is quite good. utop # result >>| ident;; - : (Cohttp.Response.t * string Pipe.Reader.t, exn) Result.t =3D Core.Std.= Result.Error (li= b/monitor.ml.Error_=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 ((exn ("connection attempt timeout" 127.0.0.2:80)) (backtrace ("")) (monitor (((name try_with) (here ()) (id 553) (has_seen_error true) (someone_is_listening true) (kill_index 0)) ((name main) (here ()) (id 1) (has_seen_error false) (someone_is_listening false) (kill_index 0)))))) So i could have pattern-matched Error x where x has type exn (exception). B= ut how do i extract the exception description which is =93connection timeou= t attempt"? I would like to be able to do something like this utop # result >>| function Error e -> Error (Exn.description_string e) | Ok= x -> Ok (do_some_magic x);; So at this point my future function would return Result.t, string for Error= and something else for Ok.=20 I had a look at Core=92s documentation for Exn but its to_string returns th= e whole sexp converted into string so i am stuck :=92( As a side question for someone familiar with Core =96 why does Exn.to_strin= g return sexp in a string at all, it also has sexp_of_t, so i suppose one c= ould evaluate Sexp.to_string @@ Exn.sexp_of_t e. I am surprised that i do n= ot see a function to extract the valuable description field from the excep= tion and yet there is this apparent duplication of effort. Or am i talking = non-sense? Kind regards, Ollie=