-
-
Notifications
You must be signed in to change notification settings - Fork 647
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
racket/file: check file-exists? #3056
Conversation
I'm generally skeptical of checking whether a file exists before opening it, because there is a race after the check if some other process or thread can delete the file. Also, there may be a significant cost involved with the check on some filesystems. I don't have a good answer for reporting the error as from |
Check `file-exists?` before passing the file on to `file-size` and/or `open-input-file`. The latter led to confusing error messages, e.g.: ``` (file->string "DNE") ;; file-size: cannot get size ``` affects: `file->value` `file->list` `file->string` `file->bytes` `file->lines` `file->bytes-lines`
Instead of checking first, what about intercepting the error and rewriting it? When I try this, here's what I get:
Racket seems to have all of the information necessary to reconstruct the kind of error—there's even an |
Hm, ok. The latest commit ignores errors from If the user sees an error, it'll say "cannot open input file" (similar to And if there's a race that creates the file after the call to |
Instead or rewriting the error, is it possible to make a version that has an argument with the name of the function to blame? Something like |
Maybe, but I think that'd require a change to I'd rather close this PR than try getting into that. (But I would be happy to follow the error-rewriting approach if there's consensus that it's better; ignoring the file-size error seems best to me) |
Can you add an error message test that would have failed prior to this? Or at least post an example here? |
I've added error-message tests. My first comment has the key parts of an example, but here it is in full: Example program
Previous error (v7.6)
Current error (42b66ea)
This current error does not point to |
ping! Shall we merge this then? |
Check
file-exists?
before passing the file on tofile-size
and/oropen-input-file
. The latter led to confusing error messages, e.g.:affects:
file->value
file->list
file->string
file->bytes
file->lines
file->bytes-lines