alan-turing-institute / whatwhat

A reimagining of nowwhat in OCaml
MIT License
0 stars 0 forks source link

Allow `| head` commands from terminal #107

Closed KatrionaGoldmann closed 10 months ago

KatrionaGoldmann commented 1 year ago

Using whatwhat person ... | head returns an error:

Fatal error: exception Sys_error("Broken pipe")

Suspected cause is due to broken pipe signal (see SO question)

We probably want to catch this exception and ignore the error

yongrenjie commented 10 months ago

Digging into this more deeply, you can't even catch the exception and call exit, because exit causes stdout/stderr to be flushed and this flushing triggers the broken pipe error again.

The opam tool has handled this before: https://github.com/ocaml/opam/issues/4216

And the associated PR is probably a good reference of how to fix it: https://github.com/ocaml/opam/pull/4901 The strategy, it seems, is to silently flush stdout and stderr before exiting.