Skip to content

Timestamps timezone in exception doesn't match #9772

marclipovsky opened this Issue Mar 18, 2013 · 4 comments

3 participants


When a Time object has a set timezone (e.g. EST) and an exception is raised on that object, the timestamp in the exception message has UTC timezone instead of the set timezone.

irb(main):018:0> time ='EST')
=> Mon, 18 Mar 2013 07:53:14 EST -05:00
NoMethodError: undefined method `foo' for 2013-03-18 07:53:14 UTC:Time
    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/time_with_zone.rb:332:in `method_missing'
    from (irb):19
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Here is time in UTC

irb(main):021:0> time.in_time_zone('UTC')
=> Mon, 18 Mar 2013 12:53:14 UTC +00:00
Ruby on Rails member
senny commented Mar 18, 2013

confirmed! This is because TimeWithZone has a method_missing hook that delegates to the wrapped time. We could:

  1. only delegate methods that time.responds_to?().
  2. rescue NoMethodError and raise it from the context of TimeWithZone

@pixeltrix I'd implement 1.) but I think there are API's that rely on method missing. Let me know what you think and I submit a PR.

Ruby on Rails member

@senny I think option 2 is the safest - can you think of any other error messages that might need re-raising (i.e. include self.inspect in their message)?

Ruby on Rails member
senny commented Mar 18, 2013

@pixeltrix I'm on it (implementing 2.). I don't think other errors need re-raising as this problem only occurs in combination with method_missing which eventually raises NoMethodError. If other errors occur it should not switch context.

@senny senny added a commit that closed this issue Mar 18, 2013
@senny senny `TimeWithZone` raises `NoMethodError` in proper context.
Closes #9772.

`TimeWithZone` delegates everything to the wrapped `Time` object
using `method_missing`. The result is that `NoMethodError` error
will be raised in the context of `Time` which leads to a misleading
debug output.
@senny senny closed this in 836ea9f Mar 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.