0

I'm using mirage-channel and Channel.flush returns a (unit, Channel.write_error) Result.result. I can't figure out how to convert that Channel.write_error to a string, seems like there is a pp_write_error but I just don't get how to use it. Thanks

Ulrar
  • 895
  • 8
  • 17
  • 1
    Seems like it uses [the `fmt` library](http://erratique.ch/software/fmt/doc/Fmt.html#nameconv) (via `mirage-flow`) and that you're supposed to use `Fmt.pf` with a [formatting string](https://ocaml.org/learn/tutorials/format.html) similarly to how you'd use `printf`, which involves a bit of type trickery and compiler magic to work. It would have been nice if the documentation had even just one example to aid in understanding the types and their use. – glennsl Oct 28 '18 at 12:19
  • Fiddled a lot with it and got something that seems to compile : `| Error e -> Lwt.return_error (Fmt.strf "%a" Channel.pp_write_error e)`. Does that look okay ? I couldn't figure out Fmt.pf, it wants a Formatter and I have no idea what to use, strf doesn't – Ulrar Oct 28 '18 at 12:53
  • 1
    Yeah, sorry, that seems about like how I'd expect it to look. `strf` seems like the analog of `sprintf`, while `pf` is more like `fprintf` which'll print to a given channel. – glennsl Oct 28 '18 at 13:03
  • Great, thanks ! I'll try to force some tcp errors at some point to test it out properly, but for now it'll do – Ulrar Oct 28 '18 at 13:06

0 Answers0