Actions
Bug #11935
closedDate.new returns inconsistent errors when passed invalid arguments
    Bug #11935:
    Date.new returns inconsistent errors when passed invalid arguments
  
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
        
           Updated by CJKinni (C Kinniburgh) almost 10 years ago
          Updated by CJKinni (C Kinniburgh) almost 10 years ago
          
          
        
        
      
      - Description updated (diff)
        
           Updated by CJKinni (C Kinniburgh) over 9 years ago
          Updated by CJKinni (C Kinniburgh) over 9 years ago
          
          
        
        
      
      - Tracker changed from Feature to Bug
- Assignee changed from tadf (tadayoshi funaba) to matz (Yukihiro Matsumoto)
- ruby -v set to 2.4.0dev
- Backport set to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
Tadayoshi Funaba appears to have been gone for a year, so it's unclear who this should be assigned to.
        
           Updated by jeremyevans0 (Jeremy Evans) over 6 years ago
          Updated by jeremyevans0 (Jeremy Evans) over 6 years ago
          
          
        
        
      
      - Has duplicate Misc #15298: Inconsistent date errors added
        
           Updated by jeremyevans0 (Jeremy Evans) over 6 years ago
          Updated by jeremyevans0 (Jeremy Evans) over 6 years ago
          
          
        
        
      
      - Assignee deleted (matz (Yukihiro Matsumoto))
I agree that we should make these errors consistent and have submitted a pull request to do so: https://github.com/ruby/date/pull/9
        
           Updated by jeremyevans0 (Jeremy Evans) about 6 years ago
          Updated by jeremyevans0 (Jeremy Evans) about 6 years ago
          
          
        
        
      
      - Status changed from Open to Closed
Actions