Clarification on the codes of the errors thrown by listDirectory?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Clarification on the codes of the errors thrown by listDirectory?

sonne
Hello!

In `directory` package, there is a function
`System.Directory.listDirectory`. It says on the box that it throws
error messages that can be branched on. (`isDoesNotExistError`,
`InappropriateType` and so on.) I dug into it a little, and it appears
to me that, in actuality, on Windows (unlike on a Posix compliant
operating system) there is no reliable way to sort the errors in some
pre-defined categories like "no such file", "not a directory", et
cetera.

Therefore I must presume that either the documentation is incomplete
and misleading, or it is I who is somehow misled. The information I
have is summarized in a Stack Overflow question linked below. I would
like to receive a clarification. Perhaps an amendment to the
documentation should be considered?

The point that initially aroused my suspicion is that `NoSuchThing` is
associated with both `eNoEnt` and `eNotDir`. Is there a rationale
behind this? From the `man 3 opendir`, I do not see the need for this
ambiguity.

This is the S.O. question I mentioned: stackoverflow.com/q/49212400
There is also a linked question that elaborates on the motivation
behind my inquiry.

Thank you!
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Clarification on the codes of the errors thrown by listDirectory?

Gershom Bazerman
The mappings of windows to c errors are enumerated in the errtable in the cbits of base like so:


It is invoked from maperrno_func in the same file, which sends all other errors to EACCES, ENOEXEC or EINVAL.

Since it never sends anything to ENOTDIR, it seems clear that from the windows side, we will never get an `InappropriateType` error. Meanwhile, on the posix side, we of course may: http://hackage.haskell.org/package/base-4.10.1.0/docs/src/Foreign.C.Error.html#errnoToIOError

I think a PR to the docs that clarified which codes are not returned on windows, and what would be returned instead would be welcomed.

Cheers,
G

On March 10, 2018 at 2:26:34 PM, sonne ([hidden email]) wrote:

Hello!

In `directory` package, there is a function
`System.Directory.listDirectory`. It says on the box that it throws
error messages that can be branched on. (`isDoesNotExistError`,
`InappropriateType` and so on.) I dug into it a little, and it appears
to me that, in actuality, on Windows (unlike on a Posix compliant
operating system) there is no reliable way to sort the errors in some
pre-defined categories like "no such file", "not a directory", et
cetera.

Therefore I must presume that either the documentation is incomplete
and misleading, or it is I who is somehow misled. The information I
have is summarized in a Stack Overflow question linked below. I would
like to receive a clarification. Perhaps an amendment to the
documentation should be considered?

The point that initially aroused my suspicion is that `NoSuchThing` is
associated with both `eNoEnt` and `eNotDir`. Is there a rationale
behind this? From the `man 3 opendir`, I do not see the need for this
ambiguity.

This is the S.O. question I mentioned: stackoverflow.com/q/49212400
There is also a linked question that elaborates on the motivation
behind my inquiry.

Thank you!
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries