Rails记录器中间件错误

时间:2017-05-21 15:42:10

标签: ruby-on-rails ruby ruby-on-rails-4 activerecord

在控制器中,我已经定义了一个看起来像这样的方法:

def blah
  begin
    # do something
    # works fine till here, no issues
    # breaks in the next line, (while rendering json??)
    render json: { status: 1 }
  rescue StandardError => e
    # code never reaches here(??)
    # log exception
  end
end

即使是begin-rescue块也无法捕获此错误。 真正让我感到困惑的是,堆栈跟踪中的代码库没有一行。有什么指针吗?

完整的堆栈跟踪:

  
    

未定义的方法`logger'为[“{\”status \“:1}”]:数组

  

activesupport(4.0.13)lib / active_support / configurable.rb,第112行

  107           options = names.extract_options!
  108   
  109           names.each do |name|
  110             raise NameError.new('invalid config attribute name') unless name =~ /^[_A-Za-z]\w*$/
  111   
> 112             reader, reader_line = "def #{name}; config.#{name}; end", __LINE__
  113             writer, writer_line = "def #{name}=(value); config.#{name} = value; end", __LINE__
  114   
  115             singleton_class.class_eval reader, __FILE__, reader_line
  116             singleton_class.class_eval writer, __FILE__, writer_line
  117

App backtrace

完全回溯

- activesupport (4.0.13) lib/active_support/configurable.rb:112:in `logger'
- geokit-rails (2.0.1) lib/geokit-rails/geocoder_control.rb:15:in `set_geokit_domain'
- activesupport (4.0.13) lib/active_support/callbacks.rb:397:in `_run__489562034147364391__process_action__callbacks'
- activesupport (4.0.13) lib/active_support/callbacks.rb:80:in `run_callbacks'
- actionpack (4.0.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
- actionpack (4.0.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
- actionpack (4.0.13) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
- activesupport (4.0.13) lib/active_support/notifications.rb:159:in `block in instrument'
- activesupport (4.0.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
- activesupport (4.0.13) lib/active_support/notifications.rb:159:in `instrument'
- actionpack (4.0.13) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
- actionpack (4.0.13) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
- activerecord (4.0.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
- actionpack (4.0.13) lib/abstract_controller/base.rb:136:in `process'
- actionpack (4.0.13) lib/abstract_controller/rendering.rb:44:in `process'
- actionpack (4.0.13) lib/action_controller/metal.rb:195:in `dispatch'
- actionpack (4.0.13) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
- actionpack (4.0.13) lib/action_controller/metal.rb:231:in `block in action'
- actionpack (4.0.13) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
- actionpack (4.0.13) lib/action_dispatch/routing/route_set.rb:50:in `call'
- actionpack (4.0.13) lib/action_dispatch/journey/router.rb:71:in `block in call'
- actionpack (4.0.13) lib/action_dispatch/journey/router.rb:59:in `call'
- actionpack (4.0.13) lib/action_dispatch/routing/route_set.rb:676:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack-pjax (0.8.0) lib/rack/pjax.rb:12:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- omniauth (1.2.1) lib/omniauth/strategy.rb:186:in `call!'
- omniauth (1.2.1) lib/omniauth/strategy.rb:164:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/rack/browser_monitoring.rb:32:in `traced_call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- exception_notification (4.1.1) lib/exception_notification/rack.rb:32:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
- warden (1.2.3) lib/warden/manager.rb:34:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack (1.5.5) lib/rack/etag.rb:23:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack (1.5.5) lib/rack/conditionalget.rb:25:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack (1.5.5) lib/rack/head.rb:11:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- remotipart (1.3.0) lib/remotipart/middleware.rb:32:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/flash.rb:241:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
- rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/cookies.rb:486:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- activerecord (4.0.13) lib/active_record/query_cache.rb:36:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- activerecord (4.0.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- activerecord (4.0.13) lib/active_record/migration.rb:373:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
- activesupport (4.0.13) lib/active_support/callbacks.rb:373:in `_run__2519945963821911877__call__callbacks'
- activesupport (4.0.13) lib/active_support/callbacks.rb:80:in `run_callbacks'
- actionpack (4.0.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/reloader.rb:64:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- bugsnag (4.2.1) lib/bugsnag/rack.rb:33:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- better_errors (2.0.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
- better_errors (2.0.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
- better_errors (2.0.0) lib/better_errors/middleware.rb:57:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- railties (4.0.13) lib/rails/rack/logger.rb:38:in `call_app'
- railties (4.0.13) lib/rails/rack/logger.rb:22:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- request_store (1.2.0) lib/request_store/middleware.rb:8:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/request_id.rb:21:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack (1.5.5) lib/rack/runtime.rb:17:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- activesupport (4.0.13) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack (1.5.5) lib/rack/lock.rb:17:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- actionpack (4.0.13) lib/action_dispatch/middleware/static.rb:84:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- railties (4.0.13) lib/rails/engine.rb:511:in `call'
- railties (4.0.13) lib/rails/application.rb:97:in `call'
- newrelic_rpm (3.16.2.321) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
- rack (1.5.5) lib/rack/lock.rb:17:in `call'
- rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
- /{path-to-ruby}/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
- /{path-to-ruby}/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
- /{path-to-ruby}/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

2 个答案:

答案 0 :(得分:1)

因此...

更改方法名称后问题得以解决。

该方法名为config,因为API端点需要具有此名称。我将方法名称更改为app_config,它开始工作。不知道为什么会发生这种情况,但从那以后它一直按预期工作。

答案 1 :(得分:0)

一个可能的原因可能是better_errors

如果在救援块中引发错误,则其cause将是原始错误。 better_errors改为显示cause,这意味着回溯将不在抢救块中。这给您一种幻想,它永远都无法挽救。

有关更多详细信息,请参见https://github.com/BetterErrors/better_errors/pull/459