fix too restrictive type in CCResult

This commit is contained in:
Simon Cruanes 2017-04-13 15:23:22 +02:00
parent c7b1afca82
commit af6cd08ff4
2 changed files with 10 additions and 2 deletions

View file

@ -24,6 +24,10 @@ let fail_printf format =
(fun buf -> fail (Buffer.contents buf))
buf format
(*$T
(Error "ohno 42") = (fail_printf "ohno %d" 42)
*)
let fail_fprintf format =
let buf = Buffer.create 64 in
let out = Format.formatter_of_buffer buf in
@ -31,6 +35,10 @@ let fail_fprintf format =
(fun out -> Format.pp_print_flush out (); fail (Buffer.contents buf))
out format
(*$T
(Error "ohno 42") = (fail_fprintf "ohno %d" 42)
*)
let add_ctx msg x = match x with
| Error e -> Error (e ^ "\ncontext:" ^ msg)
| Ok x -> Ok x

View file

@ -34,11 +34,11 @@ val of_exn_trace : exn -> ('a, string) t
Remember to call [Printexc.record_backtrace true] and compile with the
debug flag for this to work. *)
val fail_printf : ('a, Buffer.t, unit, ('a, string) t) format4 -> 'a
val fail_printf : ('a, Buffer.t, unit, ('b, string) t) format4 -> 'a
(** [fail_printf format] uses [format] to obtain an error message
and then returns [Error msg] *)
val fail_fprintf : ('a, Format.formatter, unit, ('a, string) t) format4 -> 'a
val fail_fprintf : ('a, Format.formatter, unit, ('b, string) t) format4 -> 'a
(** [fail_printf format] uses [format] to obtain an error message
and then returns [Error msg] *)