Project

General

Profile

Actions

Bug #11935

closed

Date.new returns inconsistent errors when passed invalid arguments

Added by CJKinni (C Kinniburgh) almost 9 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:72641]

Description

When passed invalid data, such as floats and nil values, the Date.new function returns a variety of results that aren't particularly easy to read and understand. The 'undefined method 'div' for nil:NilClass' is particularly unhelpful.

irb(main):002:0> Date.new(1,nil,1)
TypeError: no implicit conversion from nil to integer
irb(main):003:0> Date.new(1,1,nil)
NoMethodError: undefined method `div' for nil:NilClass
irb(main):004:0> Date.new(nil,1,1)
NoMethodError: undefined method `<' for nil:NilClass

I have attached a potential fix. It returns a more consistent set of "invalid day", "invalid month", and "invalid year" argument errors.


Files

date-new-argument-errors.patch (1.14 KB) date-new-argument-errors.patch Patch to ext/date/date_core.c from ruby 2.4.0dev CJKinni (C Kinniburgh), 12/31/2015 06:01 PM

Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Misc #15298: Inconsistent date errorsClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0