Project

General

Profile

Actions

Bug #19354

closed

Issues with arguments validation in IO.read

Added by andrykonchin (Andrew Konchin) over 2 years ago. Updated over 2 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:111907]

Description

I've noticed a strange error message when IO.read is called with additional positional argument:

IO.read("a.txt", 3, 0, {mode: "r+"})
# (irb):2:in `read': wrong number of arguments (given 3, expected 0..2) (ArgumentError)

But I would expect receiving given 4, expected 1..3 as far as the first argument (file name) is mandatory and all the other arguments - are optional.

I've encountered another related issue - looks like existing of a file with specified name is checked before number of arguments.

So when passed additional argument and specified a name of not existing file - I receive error about wrong file name, but would expect more basic and essential error about wrong number of arguments:

IO.read("b.txt", 3, 0, {mode: "r+"})
# (irb):3:in `read': No such file or directory @ rb_sysopen - b.txt (Errno::ENOENT)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0