[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MirageOS-devel] Error handling in Mirage - request for comments!



On Tue, Feb 3, 2015 at 2:25 PM, Thomas Leonard <talex5@xxxxxxxxx> wrote:
Â
> open Core.Std;;
>
> type myerr = [`Zero | `Neg of int] with sexp;;
>
> (* Get back to myerr if possible. *)
> let myerr_of_error (e:Error.t) : myerr option =
>Â Âmatch Error.sexp_of_t e with
>Â Â| Sexp.List (_::x::[]) -> Some (myerr_of_sexp x)
>Â Â| _ -> None

I don't understand how this works. How does myerr_of_error know that
this is a myerr? It seems to be just testing that the sexp is a 2-item
list.

It's a best effort implementation. Error.create puts a string as the first item of the list and your specific error value as the second item. I haven't checked what happens when you apply Error.tag. I'd have to investigate more to see if there's a reasonably predictable sexp structure, so you can know which part is the myerr.


Does it throw an exception if given some different type of
error?

I decided to return None, but maybe we could again return an Error.t.

_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.