Skip to content

Add missing File::NotFoundError exception documentation for File.open #15826

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,14 @@ class File < IO::FileDescriptor
end

# Returns the content of *filename* as a string.
#
# Raises `File::NotFoundError` if the file at filename does not exist.
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be more accurate to say something around the lines of?

Raises File::Error if the file cannot be accessed for whatever reason.

#
# ```
# File.write("bar", "foo")
# File.read("bar") # => "foo"
#
# File.read("notexist") # raises File::NotFoundError
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# File.read("notexist") # raises File::NotFoundError
# File.read("non-existent-file") # raises File::NotFoundError

# ```
def self.read(filename : Path | String, encoding = nil, invalid = nil, blocking = true) : String
open(filename, "r", blocking: blocking) do |file|
Expand Down
Loading