Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg: minor fix is sys_poll library #11497

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gridbugs
Copy link
Collaborator

Io.String_path.lines_of_file raises Sys_error rather than Unix_error, so the way we were handling errors in sys_poll would not correctly handle cases where files are missing. Since Sys_error does not provide information about the nature of the error, explicitly check that the file exists and is a regular file rather than relying on exceptions.

`Io.String_path.lines_of_file` raises `Sys_error` rather than
`Unix_error`, so the way we were handling errors in sys_poll would not
correctly handle cases where files are missing. Since `Sys_error` does
not provide information about the nature of the error, explicitly check
that the file exists and is a regular file rather than relying on
exceptions.

Signed-off-by: Stephen Sherratt <[email protected]>
| exception Unix.Unix_error (Unix.ENOENT, _, _) -> None
if Sys.file_exists p && Sys.is_regular_file p
then Some (Io.String_path.lines_of_file p)
else None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to catch the Sys_error and then do the checks? That way the stat calls only happen on the exception case and don't need to be paid on every invocation of the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants