Rails ArgumentError: invalid %-encoding - ruby-on-rails

For the last month, we've had a bot scraping our site regularly, leading to a bunch of ArgumentError: invalid %-encoding errors because the URLs are malformed. I've looked at a bunch of issues in rack here and here and rails here, and looked at this SO thread but there doesn't seem to be a definitive solution. Is there a correct solution for GET errors? Do I have to monkeypatch rack?
edit: And here's a backtrace:
/usr/local/lib/ruby/1.9.1/uri/common.rb:898:in `decode_www_form_component'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:41:in `unescape'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:94:in `block (2 levels) in parse_nested_query'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:94:in `map'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:94:in `block in parse_nested_query'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:93:in `each'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:93:in `parse_nested_query'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/request.rb:332:in `parse_query'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/http/request.rb:269:in `parse_query'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/request.rb:186:in `GET'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/http/request.rb:225:in `GET'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/http/parameters.rb:10:in `parameters'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/http/filter_parameters.rb:33:in `filtered_parameters'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:21:in `process_action'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
[GEM_ROOT]/gems/activerecord-3.2.12/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/abstract_controller/base.rb:121:in `process'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/abstract_controller/rendering.rb:45:in `process'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal.rb:203:in `dispatch'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal.rb:246:in `block in action'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:73:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:36:in `call'
[GEM_ROOT]/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
[GEM_ROOT]/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
[GEM_ROOT]/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:601:in `call'
[GEM_ROOT]/gems/omniauth-1.1.1/lib/omniauth/strategy.rb:177:in `call!'
[GEM_ROOT]/gems/omniauth-1.1.1/lib/omniauth/strategy.rb:157:in `call'
[GEM_ROOT]/gems/sass-3.2.7/lib/sass/plugin/rack.rb:54:in `call'
[GEM_ROOT]/gems/warden-1.2.1/lib/warden/manager.rb:35:in `block in call'
[GEM_ROOT]/gems/warden-1.2.1/lib/warden/manager.rb:34:in `catch'
[GEM_ROOT]/gems/warden-1.2.1/lib/warden/manager.rb:34:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/etag.rb:23:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/conditionalget.rb:25:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/head.rb:14:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/flash.rb:242:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/cookies.rb:341:in `call'
[GEM_ROOT]/gems/activerecord-3.2.12/lib/active_record/query_cache.rb:64:in `call'
[GEM_ROOT]/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `_run__497203393471184793__call__4495106819278994598__callbacks'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/rack/logger.rb:32:in `call_app'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `block in call'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/tagged_logging.rb:22:in `tagged'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/request_id.rb:22:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:143:in `pass'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:172:in `rescue in lookup'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:168:in `lookup'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/engine.rb:479:in `call'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/application.rb:223:in `call'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/utils.rb:479:in `safe_fork'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:180:in `start'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/helper-scripts/passenger-spawn-server:99:in `<main>'

if you don't mind against monkeypatching Rack then create in config/initializers file (for example rack.rb) with this content:
module Rack
module Utils
if defined?(::Encoding)
def unescape(s, encoding = Encoding::UTF_8)
begin
URI.decode_www_form_component(s, encoding)
rescue ArgumentError
URI.decode_www_form_component(URI.encode(s), encoding)
end
end
else
def unescape(s, encoding = nil)
begin
URI.decode_www_form_component(s, encoding)
rescue ArgumentError
URI.decode_www_form_component(URI.encode(s), encoding)
end
end
end
module_function :unescape
end
end
p.s. it works with passenger, but with Webrick and Thin it doesn't. It looks like both webrick and thin parse a request too, so the failure happens before initializer is loaded. For example with Thin error happens in thin-1.6.2/lib/thin/request.rb:84.

You could inject a middleware designed to detect these and fail gracefully. The basic idea is to just try to parse the query string, and if it fails, bail out with a HTTP 400. Otherwise, just allow the request through.
class RefuseInvalidRequest
def initialize(app)
#app = app
end
def call(env)
query = Rack::Utils.parse_nested_query(env['QUERY_STRING'].to_s) rescue :bad_query
if query == :bad_query
[400, {'Content-Type' => 'text/plain'}, "Bad Request"]
else
#app.call(env)
end
end
end
I haven't tested this, but the concept should work.

Related

Ruby crash on server

After 10 years my setup has started crashing every couple of weeks. The error I receive is below. The company that created the system has gone under and I do not have clue where to start getting this fixed. Any ideas would a great help.
The error encountered was: Errno::ECONNREFUSED - Connection refused - connect(2)
Backtrace:
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:560:in `initialize'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:560:in `open'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:560:in `connect'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/timeout.rb:53:in `timeout'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/timeout.rb:101:in `timeout'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:560:in `connect'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:553:in `do_start'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:542:in `start'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:440:in `start'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/bundler/gems/Show-Control-b7149704e299/lib/show_control/api/client.rb:122:in `request'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/bundler/gems/Show-Control-b7149704e299/lib/show_control/api/client.rb:105:in `get'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/bundler/gems/Show-Control-b7149704e299/lib/show_control/api/client.rb:73:in `find_all'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/bundler/gems/Show-Control-b7149704e299/lib/show_control/api/client.rb:38:in `find_all_templates'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/app/controllers/admin/scheduler/templates_controller.rb:4:in `index'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/abstract_controller/base.rb:150:in `process_action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_controller/metal/rendering.rb:11:in `process_action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/abstract_controller/callbacks.rb:18:in `process_action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:436:in `_run__577361292__process_action__199225275__callbacks'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:410:in `send'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:94:in `send'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:94:in `run_callbacks'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/abstract_controller/callbacks.rb:17:in `process_action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/notifications.rb:52:in `instrument'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/notifications.rb:52:in `instrument'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_controller/metal/rescue.rb:17:in `process_action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/abstract_controller/base.rb:119:in `process'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/abstract_controller/rendering.rb:41:in `process'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_controller/metal.rb:138:in `dispatch'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_controller/metal.rb:178:in `action'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:62:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:27:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-mount-0.6.14/lib/rack/mount/route_set.rb:148:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-mount-0.6.14/lib/rack/mount/code_generation.rb:93:in `recognize'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-mount-0.6.14/lib/rack/mount/code_generation.rb:82:in `optimized_each'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-mount-0.6.14/lib/rack/mount/code_generation.rb:92:in `recognize'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-mount-0.6.14/lib/rack/mount/route_set.rb:139:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:493:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/hoptoad_notifier-2.3.12/lib/hoptoad_notifier/rack.rb:27:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/haml-3.0.25/lib/sass/plugin/rack.rb:41:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/warden-1.0.3/lib/warden/manager.rb:35:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/warden-1.0.3/lib/warden/manager.rb:34:in `catch'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/warden-1.0.3/lib/warden/manager.rb:34:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/head.rb:14:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-1.2.4/lib/rack/methodoverride.rb:24:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/flash.rb:182:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/plugins/latitude/lib/latitude/middleware/flash_session_cookie_middleware.rb:18:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/cookies.rb:302:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activerecord-3.0.7/lib/active_record/query_cache.rb:32:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activerecord-3.0.7/lib/active_record/query_cache.rb:12:in `cache'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activerecord-3.0.7/lib/active_record/query_cache.rb:31:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/callbacks.rb:46:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/callbacks.rb:44:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-contrib-1.1.0/lib/rack/contrib/sendfile.rb:105:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/railties-3.0.7/lib/rails/rack/logger.rb:13:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-contrib-1.1.0/lib/rack/contrib/runtime.rb:18:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-1.2.4/lib/rack/lock.rb:11:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-1.2.4/lib/rack/lock.rb:11:in `synchronize'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/rack-1.2.4/lib/rack/lock.rb:11:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/railties-3.0.7/lib/rails/application.rb:168:in `call'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `send'
/opt/www/apps/server.XXXXXXX.lan/releases/20111223105109/vendor/bundle/ruby/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/rack/application_spawner.rb:205:in `start_request_handler'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/rack/application_spawner.rb:170:in `send'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/rack/application_spawner.rb:170:in `handle_spawn_application'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/utils.rb:479:in `safe_fork'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/rack/application_spawner.rb:165:in `handle_spawn_application'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server.rb:180:in `start'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/rack/application_spawner.rb:128:in `start'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/spawn_manager.rb:253:in `spawn_rack_application'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/spawn_manager.rb:246:in `spawn_rack_application'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/opt/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.5/helper-scripts/passenger-spawn-server:99
Back

Print stack trace in reverse with Ruby 3, Rails 6 and Puma

Is there an easy way to reverse the stack trace when printed by puma? It's quite tedious scroll up the whole stack trace just to see that you have made a typo. Here is an example:
uninitialized constant Treasure
/workspace/app/graphql/types/query_type.rb:7:in `<class:QueryType>'
/workspace/app/graphql/types/query_type.rb:3:in `<module:Types>'
/workspace/app/graphql/types/query_type.rb:1:in `<main>'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:26:in `require'
/workspace/app/graphql/workspace_schema.rb:3:in `<class:WorkspaceSchema>'
/workspace/app/graphql/workspace_schema.rb:1:in `<main>'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:26:in `require'
/workspace/app/controllers/graphql_controller.rb:12:in `execute'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/abstract_controller/base.rb:228:in `process_action'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_controller/metal/rendering.rb:30:in `process_action'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
/usr/local/bundle/gems/activesupport-6.1.3.2/lib/active_support/callbacks.rb:106:in `run_callbacks'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/abstract_controller/callbacks.rb:41:in `process_action'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_controller/metal/rescue.rb:22:in `process_action'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
/usr/local/bundle/gems/activesupport-6.1.3.2/lib/active_support/notifications.rb:203:in `block in instrument'
/usr/local/bundle/gems/activesupport-6.1.3.2/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/usr/local/bundle/gems/activesupport-6.1.3.2/lib/active_support/notifications.rb:203:in `instrument'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_controller/metal/instrumentation.rb:33:in `process_action'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
/usr/local/bundle/gems/activerecord-6.1.3.2/lib/active_record/railties/controller_runtime.rb:27:in `process_action'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/abstract_controller/base.rb:165:in `process'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_controller/metal.rb:190:in `dispatch'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_controller/metal.rb:254:in `dispatch'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/routing/route_set.rb:33:in `serve'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/journey/router.rb:50:in `block in serve'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/journey/router.rb:32:in `each'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/journey/router.rb:32:in `serve'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/routing/route_set.rb:842:in `call'
/usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in call'
/usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:34:in `catch'
/usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:34:in `call'
/usr/local/bundle/gems/rack-2.2.3/lib/rack/etag.rb:27:in `call'
/usr/local/bundle/gems/rack-2.2.3/lib/rack/conditional_get.rb:40:in `call'
/usr/local/bundle/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
/usr/local/bundle/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:601:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
/usr/local/bundle/gems/activesupport-6.1.3.2/lib/active_support/callbacks.rb:98:in `run_callbacks'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/executor.rb:14:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
/usr/local/bundle/gems/railties-6.1.3.2/lib/rails/rack/logger.rb:37:in `call_app'
/usr/local/bundle/gems/railties-6.1.3.2/lib/rails/rack/logger.rb:26:in `block in call'
/usr/local/bundle/gems/activesupport-6.1.3.2/lib/active_support/tagged_logging.rb:99:in `block in tagged'
/usr/local/bundle/gems/activesupport-6.1.3.2/lib/active_support/tagged_logging.rb:37:in `tagged'
/usr/local/bundle/gems/activesupport-6.1.3.2/lib/active_support/tagged_logging.rb:99:in `tagged'
/usr/local/bundle/gems/railties-6.1.3.2/lib/rails/rack/logger.rb:26:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/request_id.rb:26:in `call'
/usr/local/bundle/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
/usr/local/bundle/gems/activesupport-6.1.3.2/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/executor.rb:14:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/static.rb:24:in `call'
/usr/local/bundle/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
/usr/local/bundle/gems/actionpack-6.1.3.2/lib/action_dispatch/middleware/host_authorization.rb:98:in `call'
/usr/local/bundle/gems/rack-cors-1.1.1/lib/rack/cors.rb:100:in `call'
/usr/local/bundle/gems/railties-6.1.3.2/lib/rails/engine.rb:539:in `call'
/usr/local/bundle/gems/puma-5.3.1/lib/puma/configuration.rb:249:in `call'
/usr/local/bundle/gems/puma-5.3.1/lib/puma/request.rb:76:in `block in handle_request'
/usr/local/bundle/gems/puma-5.3.1/lib/puma/thread_pool.rb:338:in `with_force_shutdown'
/usr/local/bundle/gems/puma-5.3.1/lib/puma/request.rb:75:in `handle_request'
/usr/local/bundle/gems/puma-5.3.1/lib/puma/server.rb:437:in `process_client'
/usr/local/bundle/gems/puma-5.3.1/lib/puma/thread_pool.rb:145:in `block in spawn_thread'
Completed 500 Internal Server Error in 5ms (Views: 1.0ms | ActiveRecord: 0.0ms | Allocations: 2510)
It would be much more convenient if uninitialized constant Treasure were shown at the bottom. I've done some research and it seems like it should have been implemented with Ruby 2.5. Maybe I can configure puma somehow to do this?
I'm using Ruby 3 and Rails 6.
One possibility is to add a middleware to the end of your middleware list, catch the exception there and reverse it.
module MyApp
class FlipExceptions
def initialize(app)
#app = app
end
def call(env)
return #app.call(env)
rescue StandardError => e
trace = e.backtrace.reverse
e.set_backtrace(trace)
raise e
end
end
end

Grape rescue Grape::Exceptions::ValidationErrors not working

I wrote an api to upload a image file to server.
when I am upload without a file, it will be error
I tried to rescue it like this:
rescue_from Grape::Exceptions::ValidationErrors do |e|
error! e.message, 404
end
but it doesn't work.
Here is error message:
E, [2015-11-23T22:17:44.337050 #10646] ERROR -- : avatar is invalid (Grape::Exceptions::ValidationErrors)
remote_address: 127.0.0.1
token: Basic bGl4aWJveDpsaXhpYXBpMTIzNA==
method: POST
path: /api/v1/users/change_avatar.json
query: {"avatar"=>"undefined"}
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/endpoint.rb:249:in `block in run'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/endpoint.rb:219:in `run'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/endpoint.rb:201:in `block in call!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/base.rb:24:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/base.rb:24:in `call!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/base.rb:18:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/base.rb:24:in `call!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/base.rb:18:in `call'
/Users/macstore1/projects/lixibox/app/controllers/api/v1/api_error_handler.rb:9:in `call!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/base.rb:18:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/error.rb:27:in `block in call!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/error.rb:26:in `catch'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/error.rb:26:in `call!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/middleware/base.rb:18:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/builder.rb:153:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/endpoint.rb:202:in `call!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/endpoint.rb:190:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:75:in `optimized_each'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/api.rb:114:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/api.rb:44:in `call!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/grape-0.13.0/lib/grape/api.rb:39:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/routing/mapper.rb:51:in `serve'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/journey/router.rb:43:in `block in serve'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/journey/router.rb:30:in `each'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/journey/router.rb:30:in `serve'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:819:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:186:in `call!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:164:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/etag.rb:24:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/conditionalget.rb:38:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/remotipart-1.2.1/lib/remotipart/middleware.rb:27:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/flash.rb:260:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/cookies.rb:560:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activerecord-4.2.1/lib/active_record/query_cache.rb:36:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:88:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/reloader.rb:73:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/airbrake-4.3.0/lib/airbrake/rails/middleware.rb:13:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/better_errors-2.1.1/lib/better_errors/middleware.rb:84:in `protected_app_call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/better_errors-2.1.1/lib/better_errors/middleware.rb:79:in `better_errors_call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/better_errors-2.1.1/lib/better_errors/middleware.rb:57:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/web-console-2.2.1/lib/web_console/middleware.rb:39:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/rack/logger.rb:38:in `call_app'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/rack/logger.rb:20:in `block in call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:26:in `tagged'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:68:in `tagged'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/rack/logger.rb:20:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/quiet_assets-1.1.0/lib/quiet_assets.rb:27:in `call_with_quiet_assets'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/activesupport-4.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/actionpack-4.2.1/lib/action_dispatch/middleware/static.rb:113:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/airbrake-4.3.0/lib/airbrake/user_informer.rb:16:in `_call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/airbrake-4.3.0/lib/airbrake/user_informer.rb:12:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/engine.rb:518:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/application.rb:164:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/thin-1.6.3/lib/thin/connection.rb:86:in `block in pre_process'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/thin-1.6.3/lib/thin/connection.rb:84:in `catch'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/thin-1.6.3/lib/thin/connection.rb:84:in `pre_process'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/thin-1.6.3/lib/thin/connection.rb:53:in `process'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/thin-1.6.3/lib/thin/connection.rb:39:in `receive_data'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run_machine'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/thin-1.6.3/lib/thin/backends/base.rb:73:in `start'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/thin-1.6.3/lib/thin/server.rb:162:in `start'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/handler/thin.rb:19:in `run'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/commands/server.rb:80:in `start'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:80:in `block in server'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `tap'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `server'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
/Users/macstore1/projects/lixibox/bin/rails:8:in `require'
/Users/macstore1/projects/lixibox/bin/rails:8:in `<top (required)>'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/spring-1.3.6/lib/spring/client/rails.rb:28:in `load'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/spring-1.3.6/lib/spring/client/rails.rb:28:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/spring-1.3.6/lib/spring/client/command.rb:7:in `call'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/spring-1.3.6/lib/spring/client.rb:26:in `run'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/spring-1.3.6/bin/spring:48:in `<top (required)>'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/spring-1.3.6/lib/spring/binstub.rb:11:in `load'
/Users/macstore1/.rvm/gems/ruby-2.1.6#lixibox/gems/spring-1.3.6/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/macstore1/projects/lixibox/bin/spring:13:in `require'
/Users/macstore1/projects/lixibox/bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Maybe there is an error in your API somewhere. The following should work (tested with Grape 0.13.0):
module Api
class API < Grape::API
rescue_from Grape::Exceptions::ValidationErrors do |e|
error! e.message, 404
end
resource '/avatars' do
params do
requires :avatar, type: Rack::Multipart::UploadedFile
end
post '/' do
{
filename: params.avatar.filename,
file_type: params.avatar.type
}
end
end
end
end
Also, if you define a rescue_from :all block, be sure to do it as the last block. By the way, Grape has a pretty good documentation.

I am getting this warning Warning: Error loading

I am upgrading from rails 2.3 to rails 3.2. I have models divided into sub folders. Just like there is a model app/models/ad/ad.rb the other app/models/ad/ad_city.rb but inside the model it is written as:
class Ad < ActiveRecord::Base
class AdCity < ActiveRecord::Base
and not:
class Ad::Ad < ActiveRecord::Base
class Ad::AdCity < ActiveRecord::Base
I have in my application.rb:
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
even I tried including each folder in config.autoload_paths. But it give me a thousand lines warning:
Warning: Error loading /home/deep/projects/upgrade/models/myapp/app/models/ad/ad_city.rb:
uninitialized constant Ad::AdCity
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:229:in `each'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:229:in `constantize'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx/context.rb:64:in `block (2 levels) in load_models'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx/context.rb:54:in `each'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx/context.rb:54:in `block in load_models'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx/context.rb:53:in `each'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx/context.rb:53:in `load_models'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx/context.rb:15:in `prepare'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx.rb:81:in `block in context'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx.rb:78:in `synchronize'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx.rb:78:in `context'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/thinking-sphinx-2.0.11/lib/thinking_sphinx/active_record.rb:162:in `define_index'
/home/deep/projects/upgrade/models/myapp/app/models/user/user_indexes.rb:6:in `included'
/home/deep/projects/upgrade/models/myapp/app/models/user/user.rb:295:in `include'
/home/deep/projects/upgrade/models/myapp/app/models/user/user.rb:295:in `<class:User>'
/home/deep/projects/upgrade/models/myapp/app/models/user/user.rb:1:in `<top (required)>'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/bundler/gems/rails-dev-boost-bf49caca6670/lib/rails_development_boost/dependencies_patch.rb:364:in `block in load_file_with_constant_tracking_internal'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/bundler/gems/rails-dev-boost-bf49caca6670/lib/rails_development_boost/dependencies_patch.rb:240:in `now_loading'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/bundler/gems/rails-dev-boost-bf49caca6670/lib/rails_development_boost/dependencies_patch.rb:364:in `load_file_with_constant_tracking_internal'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/bundler/gems/rails-dev-boost-bf49caca6670/lib/rails_development_boost/dependencies_patch.rb:234:in `block in load_file_with_constant_tracking'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/bundler/gems/rails-dev-boost-bf49caca6670/lib/rails_development_boost/dependencies_patch.rb:383:in `async_synchronize'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/bundler/gems/rails-dev-boost-bf49caca6670/lib/rails_development_boost/dependencies_patch.rb:229:in `load_file_with_constant_tracking'
/home/deep/projects/upgrade/models/myapp/lib/authenticated_system.rb:108:in `login_from_session'
/home/deep/projects/upgrade/models/myapp/lib/authenticated_system.rb:24:in `current_user'
/home/deep/projects/upgrade/models/myapp/lib/authenticated_system.rb:14:in `logged_in?'
/home/deep/projects/upgrade/models/myapp/app/controllers/application_controller.rb:288:in `set_timezone'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:429:in `_run__402496120916004207__process_action__1098406492416702350__callbacks'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/abstract_controller/callbacks.rb:17:in `process_action'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/notifications.rb:123:in `block in instrument'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/notifications.rb:123:in `instrument'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activerecord-3.2.19/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/abstract_controller/base.rb:121:in `process'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/abstract_controller/rendering.rb:45:in `process'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_controller/metal.rb:203:in `dispatch'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_controller/metal.rb:246:in `block in action'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/routing/route_set.rb:73:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/routing/route_set.rb:36:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/routing/route_set.rb:608:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/exception_notification-4.0.1/lib/exception_notification/rack.rb:28:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/bundler/gems/rails-dev-boost-bf49caca6670/lib/rails_development_boost/async.rb:14:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/rack-1.4.5/lib/rack/etag.rb:23:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/rack-1.4.5/lib/rack/conditionalget.rb:25:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/head.rb:14:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/flash.rb:242:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/cookies.rb:341:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activerecord-3.2.19/lib/active_record/query_cache.rb:64:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `_run__2960753221531180313__call__4371824738127159201__callbacks'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/reloader.rb:65:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/better_errors-2.0.0/lib/better_errors/middleware.rb:84:in `protected_app_call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/better_errors-2.0.0/lib/better_errors/middleware.rb:79:in `better_errors_call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/better_errors-2.0.0/lib/better_errors/middleware.rb:57:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/railties-3.2.19/lib/rails/rack/logger.rb:32:in `call_app'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/railties-3.2.19/lib/rails/rack/logger.rb:16:in `block in call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/tagged_logging.rb:22:in `tagged'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/railties-3.2.19/lib/rails/rack/logger.rb:16:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/request_id.rb:22:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/activesupport-3.2.19/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/actionpack-3.2.19/lib/action_dispatch/middleware/static.rb:63:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/railties-3.2.19/lib/rails/engine.rb:484:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/railties-3.2.19/lib/rails/application.rb:231:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/railties-3.2.19/lib/rails/rack/log_tailer.rb:17:in `call'
/home/deep/.rvm/gems/ruby-2.1.2#upgrade_mygemset/gems/rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
/home/deep/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/home/deep/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/home/deep/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
for all the models. It doesn't throw any error just gives warning each time my app makes any connection with the database. What should I do. Please help

Crafting Rails Chapter 7: MultiJson::DecodeError - 756: unexpected token at '"Validation failed: %{errors}"':

I'm following through the 'Crafting Rails' book, and I've come to hurdle I just can't get over in the final Chapter (Chap 7)
When I try to run the project at the end of 7.3, I get:
MultiJson::DecodeError - 756: unexpected token at '"Validation failed: %{errors}"':
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/json-1.6.5/lib/json/common.rb:148:in `parse'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/json-1.6.5/lib/json/common.rb:148:in `parse'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/multi_json-1.1.0/lib/multi_json/engines/json_common.rb:9:in `decode'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/multi_json-1.1.0/lib/multi_json.rb:79:in `decode'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.2/lib/active_support/json/decoding.rb:12:in `decode'
/Users/john/Manuals/Rails/Crafting Rails/Chap7/translator-old/lib/translator/app.rb:32:in `locale_value'
/Users/john/Manuals/Rails/Crafting Rails/Chap7/translator-old/lib/translator/app.rb:55:in `block in evaluate_source'
/Users/john/Manuals/Rails/Crafting Rails/Chap7/translator-old/lib/translator/app.rb:54:in `each'
/Users/john/Manuals/Rails/Crafting Rails/Chap7/translator-old/lib/translator/app.rb:54:in `evaluate_source'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/tilt-1.3.3/lib/tilt/template.rb:209:in `instance_eval'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/tilt-1.3.3/lib/tilt/template.rb:209:in `evaluate_source'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/tilt-1.3.3/lib/tilt/template.rb:144:in `cached_evaluate'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/tilt-1.3.3/lib/tilt/template.rb:127:in `evaluate'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/tilt-1.3.3/lib/tilt/haml.rb:24:in `evaluate'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:636:in `render'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:532:in `haml'
/Users/john/Manuals/Rails/Crafting Rails/Chap7/translator-old/lib/translator/app.rb:19:in `exhibit_translations'
/Users/john/Manuals/Rails/Crafting Rails/Chap7/translator-old/lib/translator/app.rb:10:in `block in <class:App>'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:1211:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:1211:in `block in compile!'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `[]'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `block (3 levels) in route!'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:801:in `route_eval'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `block (2 levels) in route!'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:822:in `block in process_route'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `catch'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `process_route'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:784:in `block in route!'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `each'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `route!'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:886:in `dispatch!'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `block in call!'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `block in invoke'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `catch'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:705:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/nulllogger.rb:9:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `block in call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:1416:in `synchronize'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/journey-1.0.3/lib/journey/router.rb:68:in `block in call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/journey-1.0.3/lib/journey/router.rb:56:in `each'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/journey-1.0.3/lib/journey/router.rb:56:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:594:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/sass-3.1.15/lib/sass/plugin/rack.rb:54:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/etag.rb:23:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/conditionalget.rb:25:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/head.rb:14:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/flash.rb:242:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/cookies.rb:338:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.2/lib/active_record/query_cache.rb:64:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `_run__2584460681594678013__call__1225515721622234840__callbacks'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/reloader.rb:65:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.2/lib/rails/rack/logger.rb:26:in `call_app'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.2/lib/rails/rack/logger.rb:16:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/request_id.rb:22:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.2/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.2/lib/action_dispatch/middleware/static.rb:61:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.2/lib/rails/engine.rb:479:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.2/lib/rails/application.rb:220:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.2/lib/rails/rack/log_tailer.rb:14:in `call'
/Users/john/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
/Users/john/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/john/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/john/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
I've tried stripping all symbols out of that string, but no joy - same issue. Any idea what might be going wrong here? I've literally copied & pasted from the book, so I don't think it's a typo. Could possibly be a redis issue (I'm unfamiliar with it), but it seems to be working fine.
Any ideas appreciated
In gem file declare
gem 'yajl-ruby'
It is used to Parse and encode multiple JSON objects to and from streams or strings continuous.
And require 'yajl/json_gem'
in config/application.rb

Resources