Client refactor: Move handling of unix error from Error_monad to stdlib-unix

This commit is contained in:
Grégoire Henry 2018-02-08 10:51:02 +01:00
parent 41d30777a6
commit 5c2ba214f0
2 changed files with 13 additions and 3 deletions

View File

@ -507,8 +507,6 @@ let () =
Data_encoding.(obj1 (req "msg" string))
(function
| Exn (Failure msg) -> Some msg
| Exn (Unix.Unix_error (err, fn, _)) ->
Some ("Unix error in " ^ fn ^ ": " ^ Unix.error_message err)
| Exn exn -> Some (Printexc.to_string exn)
| _ -> None)
(fun msg -> Exn (Failure msg))

View File

@ -7,7 +7,19 @@
(* *)
(**************************************************************************)
open Error_monad
let () =
register_error_kind
`Temporary
~id:"unix_error"
~title:"Unix error"
~description:"An unhandled unix exception"
~pp:Format.pp_print_string
Data_encoding.(obj1 (req "msg" string))
(function
| Exn (Unix.Unix_error (err, fn, _)) ->
Some ("Unix error in " ^ fn ^ ": " ^ Unix.error_message err)
| _ -> None)
(fun msg -> Exn (Failure msg))
let read_bytes ?(pos = 0) ?len fd buf =
let len = match len with None -> Bytes.length buf - pos | Some l -> l in