诊断在我的代码之外发生的NoMethodError

时间:2014-05-17 15:24:17

标签: ruby-on-rails ruby omniauth mapmyfitness

我使用omniauthomniauth-mapmyfitness-oauth2来允许MapMyFitness用户登录我的网站。

最近,我有一些登录尝试导致下面的错误。看起来我的Rails应用程序代码中没有出现任何错误 - 看起来它完全在ruby,某些gem或MapMyFitness API中。

非常感谢有关如何调试此 的任何指示/信息/建议。我之前没有经历过这样的问题,所以这是一个巨大的学习机会。

NoMethodError (undefined method `strip' for nil:NilClass):
  /usr/lib/ruby/1.9.1/net/http.rb:1435:in `block in initialize_http_header'
  /usr/lib/ruby/1.9.1/net/http.rb:1433:in `each'
  /usr/lib/ruby/1.9.1/net/http.rb:1433:in `initialize_http_header'
  /usr/lib/ruby/1.9.1/net/http.rb:1862:in `initialize'
  faraday (0.8.9) lib/faraday/adapter/net_http.rb:55:in `new'
  faraday (0.8.9) lib/faraday/adapter/net_http.rb:55:in `create_request'
  faraday (0.8.9) lib/faraday/adapter/net_http.rb:75:in `perform_request'
  faraday (0.8.9) lib/faraday/adapter/net_http.rb:38:in `call'
  faraday (0.8.9) lib/faraday/request/url_encoded.rb:14:in `call'
  faraday (0.8.9) lib/faraday/connection.rb:253:in `run_request'
  oauth2 (0.9.3) lib/oauth2/client.rb:90:in `request'
  oauth2 (0.9.3) lib/oauth2/client.rb:135:in `get_token'
  oauth2 (0.9.3) lib/oauth2/strategy/auth_code.rb:29:in `get_token'
  omniauth-oauth2 (1.1.2) lib/omniauth/strategies/oauth2.rb:93:in `build_access_token'
  omniauth-oauth2 (1.1.2) lib/omniauth/strategies/oauth2.rb:75:in `callback_phase'
  omniauth (1.2.1) lib/omniauth/strategy.rb:227:in `callback_call'
  omniauth (1.2.1) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.2.1) lib/omniauth/strategy.rb:164: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.8.0.218) lib/new_relic/rack/error_collector.rb:55:in `call'
  newrelic_rpm (3.8.0.218) lib/new_relic/rack/agent_hooks.rb:32:in `call'
  newrelic_rpm (3.8.0.218) lib/new_relic/rack/browser_monitoring.rb:27: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 `catch'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.5) lib/rack/etag.rb:23:in `call'
  rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
  rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.18) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.18) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.18) lib/active_support/callbacks.rb:405:in `_run__3877922931106558540__call__1275774963243928783__callbacks'
  activesupport (3.2.18) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.18) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.18) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.18) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  airbrake (3.1.16) lib/airbrake/rails/middleware.rb:13:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.18) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.18) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.18) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.18) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.18) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.18) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
  rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
  rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  airbrake (3.1.16) lib/airbrake/user_informer.rb:16:in `_call'
  airbrake (3.1.16) lib/airbrake/user_informer.rb:12:in `call'
  railties (3.2.18) lib/rails/engine.rb:484:in `call'
  railties (3.2.18) lib/rails/application.rb:231:in `call'
  railties (3.2.18) lib/rails/railtie/configurable.rb:30:in `method_missing'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:448:in `block (3 levels) in start_threads'

我确实查看了/usr/lib/ruby/1.9.1/net/http.rb文件,并在第1435行找到了对.strip的引用:

def initialize_http_header(initheader)
  @header = {}
  return unless initheader
  initheader.each do |key, value|
    warn "net/http: warning: duplicated HTTP header: #{key}" if key?(key) and $VERBOSE
    @header[key.downcase] = [value.strip]
  end
end
但是,我不知道如何处理这些信息。

1 个答案:

答案 0 :(得分:0)

omniauth-mapmyfitness-oauth2有一个奇怪的要求,即ENV['MMF_API_KEY']要为库工作。 (无论如何,对我来说很奇怪。我很想知道为什么会这样设置。)

这是因为它在line 13 of its strategy file上使用了该环境变量。

我最近迁移了服务器,忘了携带这个环境变量。基于this answer,我在新文件/etc/profile.d/mapmyfitness.sh中添加了两行,以使其在系统范围内可用:

export MMF_API_KEY=my-key
export MMF_API_SECRET=my-secret