pkg: minor fix is sys_poll library#11497
Merged
gridbugs merged 1 commit intoocaml:mainfrom Mar 3, 2025
Merged
Conversation
| | 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 |
Collaborator
There was a problem hiding this comment.
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.
Collaborator
Author
There was a problem hiding this comment.
Good point. I've changed it to optimistically read lines and to return None if Sys_error is raised. I'm not sure if I should keep the checks (Sys.file_exists p && Sys.is_regular_file p) in the exception case or just return None in response to all Sys_error exceptions.
Collaborator
There was a problem hiding this comment.
Sys.is_regular_file only exists starting with 5.1, you'd need to use stat instead, but for now I'd just leave it out until it proves to be a problem.
85c79f0 to
e5f87bf
Compare
Leonidas-from-XIV
approved these changes
Feb 25, 2025
`Io.String_path.lines_of_file` raises `Sys_error` rather than `Unix_error`. Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
e5f87bf to
35e4460
Compare
Leonidas-from-XIV
pushed a commit
to Leonidas-from-XIV/dune
that referenced
this pull request
Mar 6, 2025
`Io.String_path.lines_of_file` raises `Sys_error` rather than `Unix_error`. Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
anmonteiro
pushed a commit
to anmonteiro/dune
that referenced
this pull request
Apr 22, 2025
`Io.String_path.lines_of_file` raises `Sys_error` rather than `Unix_error`. Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
Sudha247
pushed a commit
to Sudha247/dune
that referenced
this pull request
Jul 23, 2025
`Io.String_path.lines_of_file` raises `Sys_error` rather than `Unix_error`. Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Io.String_path.lines_of_fileraisesSys_errorrather thanUnix_error, so the way we were handling errors in sys_poll would not correctly handle cases where files are missing. SinceSys_errordoes 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.