You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Date.today.compare_with_coercion nil or Date.today <=> nil sets the ruby global variable $! to #<NoMethodError: undefined method coerce for nil:NilClass>. It does not throw the exception but sets the global $! variable. Now when I raise the exception in my app code the raised exception's cause is set to #<NoMethodError: undefined method coerce' for nil:NilClass>`.
Environment Information
JRuby version - jruby-9.2.13.0
Operating system - MaC OS Catalina
Rails - 6.0.3.2
Expected Behavior
Raise the exception #<NoMethodError: undefined method coerce for nil:NilClass> rather than just setting it in $!
Actual Behavior
Sets the ruby's $! variable to #<NoMethodError: undefined method coerce for nil:NilClass> but does not raises it.
require "date"
require 'active_support'
begin
Date.today <=> nil
raise Exception
rescue Exception => e
puts e.cause
end
The comparison does not raise any non rescued exceptions but it wrongfully sets the next Exception's cause. This does not happen on any MRI >= 2.5.0.
Unfortunately, I was not able to reproduce this behavior with plain exceptions without the Date comparison. There is something special about Date implementation.
Date.today.compare_with_coercion nil
orDate.today <=> nil
sets the ruby global variable$!
to#<NoMethodError: undefined method coerce for nil:NilClass>
. It does not throw the exception but sets the global$!
variable. Now when I raise the exception in my app code the raised exception'scause
is set to#<NoMethodError: undefined method
coerce' for nil:NilClass>`.Environment Information
Expected Behavior
#<NoMethodError: undefined method coerce for nil:NilClass>
rather than just setting it in$!
Actual Behavior
$!
variable to#<NoMethodError: undefined method coerce for nil:NilClass>
but does not raises it.Script
Script Output :
The text was updated successfully, but these errors were encountered: