Skip to content

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

Open
@haakon-e

Description

@haakon-e

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messagesBetter, more actionable error messagesfilesystemUnderlying file system and functions that use it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions