BetterErrors / better_errors

Better error page for Rack apps
MIT License
6.88k stars 437 forks source link

Fix exception when large object's class is anonymous #435

Closed kdiogenes closed 5 years ago

kdiogenes commented 5 years ago

Avoids the error pointed by https://github.com/BetterErrors/better_errors/issues/411#issuecomment-462005513

When a local/instance variable is anonymous and it's value is too large better_errors prints a default message in https://github.com/BetterErrors/better_errors/blob/master/lib/better_errors/error_page.rb#L111

This pull request adds a fallback to use obj.class.to_s, since obj.class.name returns nil for anonymous classes causing the following exception:

00:23:25 web.1      | Started POST "/admin/__better_errors/50c95030d470e258/variables" for ::1 at 2019-02-09 00:23:25 -0200
00:23:26 web.1      |   
00:23:26 web.1      | TypeError (no implicit conversion of nil into String):
00:23:26 web.1      |   
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/error_page.rb:111:in `escapeHTML'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/error_page.rb:111:in `rescue in inspect_value'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/error_page.rb:107:in `inspect_value'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/error_page.rb:94:in `block in render'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/error_page.rb:93:in `each'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/error_page.rb:93:in `render'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/error_page.rb:30:in `eval'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/error_page.rb:30:in `render'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/error_page.rb:37:in `do_variables'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/middleware.rb:137:in `internal_call'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/middleware.rb:75:in `better_errors_call'
00:23:26 web.1      | better_errors (2.5.0) lib/better_errors/middleware.rb:57:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb:30:in `call'
00:23:26 web.1      | web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
00:23:26 web.1      | web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
00:23:26 web.1      | web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
00:23:26 web.1      | web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/railties/lib/rails/rack/logger.rb:38:in `call_app'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/railties/lib/rails/rack/logger.rb:26:in `block in call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/activesupport/lib/active_support/tagged_logging.rb:80:in `block in tagged'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/activesupport/lib/active_support/tagged_logging.rb:28:in `tagged'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/activesupport/lib/active_support/tagged_logging.rb:80:in `tagged'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/railties/lib/rails/rack/logger.rb:26:in `call'
00:23:26 web.1      | sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/actionpack/lib/action_dispatch/middleware/request_id.rb:27:in `call'
00:23:26 web.1      | rack (2.0.6) lib/rack/method_override.rb:22:in `call'
00:23:26 web.1      | rack (2.0.6) lib/rack/runtime.rb:22:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/actionpack/lib/action_dispatch/middleware/executor.rb:14:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/actionpack/lib/action_dispatch/middleware/static.rb:126:in `call'
00:23:26 web.1      | rack (2.0.6) lib/rack/sendfile.rb:111:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/actionpack/lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
00:23:26 web.1      | webpacker (3.5.5) lib/webpacker/dev_server_proxy.rb:22:in `perform_request'
00:23:26 web.1      | rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
00:23:26 web.1      | /home/kadu/sources/rails-dev-box/rails/railties/lib/rails/engine.rb:524:in `call'
00:23:26 web.1      | puma (3.12.0) lib/puma/configuration.rb:225:in `call'
00:23:26 web.1      | puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
00:23:26 web.1      | puma (3.12.0) lib/puma/server.rb:472:in `process_client'
00:23:26 web.1      | puma (3.12.0) lib/puma/server.rb:332:in `block in run'
00:23:26 web.1      | puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
00:23:26 web.1      | Error occurred while parsing request parameters.
00:23:26 web.1      | Contents:
00:23:26 web.1      | 
00:23:26 web.1      |
RobinDaugherty commented 5 years ago

Thanks for fixing this @cerdiogenes! I'm working to fix the CI builds on older Ruby versions, and I'll get your change merged and released ASAP.