Closed dsheets closed 7 years ago
I agree that this behavior is bad. I did some grepping in opam and it looks like changing Unix.readdir
to return an option is going to break a lot of things. As a first step we'll add a second function and deprecate readdir
There is a Unix.readdir_opt
now.
True to the
Unix.readdir
interface andreaddir(3)
before it,Unix_syscalls.readdir
returns but astring
and raisesEnd_of_file
when the directory handle is exhausted. To use it correctly, the programmer must write something like:This is particularly bad because
~extract_exn:true
must be passed totry_with
or the end-of-directory condition is effectively un-catchable as the wrapped exception that is raised is not exposed in an interface (as far as I could tell). This seems like fairly poor ergonomics that should either be corrected or very clearly documented as legacy.A final minor issue is the uncertainty about the
| Error exn -> raise exn
clause which, from an LWT programmer's point of view, looks wrong because the exception is not injected back into the monad and instead atry .. catch
is necessary insidebind
or similar to make sure that these truly exceptional cases are handled correctly and passed upward mostly un-modified. Of course, some metadata is probably lost here but I'll let you be the judge of how horrible that is.