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

More helpful error message with open(~/path/to/file.txt) #54068

Open
haakon-e opened this issue Apr 12, 2024 · 3 comments
Open

More helpful error message with open(~/path/to/file.txt) #54068

haakon-e opened this issue Apr 12, 2024 · 3 comments
Labels
domain:error messages Better, more actionable error messages domain:filesystem Underlying file system and functions that use it

Comments

@haakon-e
Copy link
Contributor

haakon-e commented Apr 12, 2024

I encountered the issue of not being able to use ~ to refer to my homedir on unix when (indirectly) calling open(~/path/to/file.txt) in the YAML.jl package: JuliaData/YAML.jl#137

Though it seems the issue won't be "fixed", I'm very happy to see that on julia +nightly, cd("~/Documents") now provides a very helpful error message (I wasn't able to find a reference to the PR that fixed this):

julia> cd("~/Documents")
ERROR: IOError: cd("~/Documents"): no such file or directory (ENOENT)
Many shells expand '~' to the home directory in unquoted strings. To replicate this behavior, call `expanduser` to expand the '~' character to the user’s home directory.

is there any chance this could be adopted in other IO methods, such as open (and others as applicable)? Now, it only says:

julia> open("~/Documents/file.txt", "r")
ERROR: SystemError: opening file "~/Documents/file.txt": No such file or directory
Stacktrace:
[...]

ref:

          The suggestion has been added to the error message printing for `~` and the cmd parser has its own issue for adding support for more special characters

Originally posted by vtjnash in #1136 (comment)

edit: apologies, didn't know it would @/vtjnash

@giordano
Copy link
Contributor

giordano commented Apr 12, 2024

I wasn't able to find a reference to the PR that fixed this

Search "Many shells expand", end up at

print(io, "\nMany shells expand '~' to the home directory in unquoted strings. To replicate this behavior, call",
then click on the "blame" button to discover that that line was introduced by #22647.

is there any chance this could be adopted in other IO methods

I'm sure chances are much higher if someone interested in this problem opens a PR 🙂

@giordano giordano added domain:filesystem Underlying file system and functions that use it domain:error messages Better, more actionable error messages labels Apr 12, 2024
@haakon-e
Copy link
Contributor Author

Thanks Mosè. I parse from what's not explicitly said in your response that you wouldn't be opposed to this proposed change -- which I find motivating for finding the time to make a PR 🙂

@jishnub
Copy link
Contributor

jishnub commented Apr 13, 2024

Please do, we could do with more error hints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:error messages Better, more actionable error messages domain:filesystem Underlying file system and functions that use it
Projects
None yet
Development

No branches or pull requests

3 participants