diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index e7d6b745..fe357443 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -2,9 +2,14 @@ ## master (unreleased) +## 2.3.0 + +* [#181](https://github.com/rails/web-console/pull/181) Log internal Web Console errors ([@schneems]) +* [#150](https://github.com/rails/web-console/pull/150) Revert #150. ([@gsamokovarov]) + ## 2.2.1 -* [#150](https://github.com/rails/web-console/pull/150) Change config.development_only default until 4.2.4 is released. +* [#150](https://github.com/rails/web-console/pull/150) Change config.development_only default until 4.2.4 is released. ([@gsamokovarov]) ## 2.2.0 @@ -48,3 +53,4 @@ [@parterburn]: https://github.com/parterburn [@sh19910711]: https://github.com/sh19910711 [@frenesim]: https://github.com/frenesim +[@schneems]: https://github.com/schneems diff --git a/lib/web_console/extensions.rb b/lib/web_console/extensions.rb index 64ccccbb..7ce7863d 100644 --- a/lib/web_console/extensions.rb +++ b/lib/web_console/extensions.rb @@ -1,6 +1,9 @@ ActionDispatch::DebugExceptions.class_eval do - def render_exception_with_web_console(env, exception) - render_exception_without_web_console(env, exception).tap do + def render_exception_with_web_console(request, exception) + render_exception_without_web_console(request, exception).tap do + # Retain superficial Rails 5 compatibility. + env = Hash === request ? request : request.env + error = ActionDispatch::ExceptionWrapper.new(env, exception).exception # Get the original exception if ExceptionWrapper decides to follow it. diff --git a/lib/web_console/middleware.rb b/lib/web_console/middleware.rb index 1ef281a2..db8e5448 100644 --- a/lib/web_console/middleware.rb +++ b/lib/web_console/middleware.rb @@ -15,34 +15,41 @@ def initialize(app) end def call(env) - request = create_regular_or_whiny_request(env) - return @app.call(env) unless request.from_whitelited_ip? - - if id = id_for_repl_session_update(request) - return update_repl_session(id, request) - elsif id = id_for_repl_session_stack_frame_change(request) - return change_stack_trace(id, request) - end + app_exception = catch :app_exception do + request = create_regular_or_whiny_request(env) + return @app.call(env) unless request.from_whitelited_ip? + + if id = id_for_repl_session_update(request) + return update_repl_session(id, request) + elsif id = id_for_repl_session_stack_frame_change(request) + return change_stack_trace(id, request) + end - status, headers, body = @app.call(env) + status, headers, body = @app.call(env) - if exception = env['web_console.exception'] - session = Session.from_exception(exception) - elsif binding = env['web_console.binding'] - session = Session.from_binding(binding) - end + if exception = env['web_console.exception'] + session = Session.from_exception(exception) + elsif binding = env['web_console.binding'] + session = Session.from_binding(binding) + end - if session && acceptable_content_type?(headers) - response = Response.new(body, status, headers) - template = Template.new(env, session) + if session && acceptable_content_type?(headers) + response = Response.new(body, status, headers) + template = Template.new(env, session) - response.headers["X-Web-Console-Session-Id"] = session.id - response.headers["X-Web-Console-Mount-Point"] = mount_point - response.write(template.render('index')) - response.finish - else - [ status, headers, body ] + response.headers["X-Web-Console-Session-Id"] = session.id + response.headers["X-Web-Console-Mount-Point"] = mount_point + response.write(template.render('index')) + response.finish + else + [ status, headers, body ] + end end + rescue => e + WebConsole.logger.error("\n#{e.class}: #{e}\n\tfrom #{e.backtrace.join("\n\tfrom ")}") + raise e + ensure + raise app_exception if Exception === app_exception end private @@ -120,5 +127,11 @@ def respond_with_unacceptable_request { output: I18n.t('errors.unacceptable_request') } end end + + def call_app(env) + @app.call(env) + rescue => e + throw :app_exception, e + end end end diff --git a/lib/web_console/railtie.rb b/lib/web_console/railtie.rb index 2ba61391..02ea3003 100644 --- a/lib/web_console/railtie.rb +++ b/lib/web_console/railtie.rb @@ -5,10 +5,6 @@ class Railtie < ::Rails::Railtie config.web_console = ActiveSupport::OrderedOptions.new config.web_console.whitelisted_ips = %w( 127.0.0.1 ::1 ) - # See rails/web-console#150 and rails/rails#20319. Revert when Ruby on - # Rails 4.2.4 is released. - config.web_console.development_only = false - initializer 'web_console.initialize' do require 'web_console/extensions' diff --git a/lib/web_console/version.rb b/lib/web_console/version.rb index ba016230..aa777c22 100644 --- a/lib/web_console/version.rb +++ b/lib/web_console/version.rb @@ -1,3 +1,3 @@ module WebConsole - VERSION = '2.2.1' + VERSION = '2.3.0' end