File tree Expand file tree Collapse file tree 6 files changed +55
-12
lines changed
Expand file tree Collapse file tree 6 files changed +55
-12
lines changed Original file line number Diff line number Diff line change 1+ ActionDispatch ::DebugExceptions . class_eval do
2+ def render_exception_with_web_console ( env , exception )
3+ render_exception_without_web_console ( env , exception ) . tap do
4+ error = ActionDispatch ::ExceptionWrapper . new ( env , exception ) . exception
5+
6+ # Get the original exception if ExceptionWrapper decides to follow it.
7+ env [ 'web_console.exception' ] = error
8+
9+ # ActionView::Template::Error bypass ExceptionWrapper original
10+ # exception following. The backtrace in the view is generated from
11+ # reaching out to original_exception in the view.
12+ if error . is_a? ( ActionView ::Template ::Error )
13+ env [ 'web_console.exception' ] = error . original_exception
14+ end
15+ end
16+ end
17+
18+ alias_method_chain :render_exception , :web_console
19+ end
Original file line number Diff line number Diff line change @@ -6,18 +6,7 @@ class Railtie < ::Rails::Railtie
66 config . web_console . whitelisted_ips = %w( 127.0.0.1 ::1 )
77
88 initializer 'web_console.initialize' do
9- ActionDispatch ::DebugExceptions . class_eval do
10- def render_exception_with_web_console ( env , exception )
11- render_exception_without_web_console ( env , exception ) . tap do
12- wrapper = ActionDispatch ::ExceptionWrapper . new ( env , exception )
13-
14- # Get the original exception if ExceptionWrapper decides to follow it.
15- env [ 'web_console.exception' ] = wrapper . exception
16- end
17- end
18-
19- alias_method_chain :render_exception , :web_console
20- end
9+ require 'web_console/extensions'
2110
2211 ActiveSupport . on_load ( :action_view ) do
2312 ActionView ::Base . send ( :include , Helper )
Original file line number Diff line number Diff line change 1+ class HelperErrorController < ApplicationController
2+ def index
3+ end
4+ end
Original file line number Diff line number Diff line change 1+ <% @ok = 42 %>
2+ <% raise %>
Original file line number Diff line number Diff line change 44 get :exception_test , to : "exception_test#index"
55 get :xhr_test , to : "exception_test#xhr"
66 get :helper_test , to : "helper_test#index"
7+ get :helper_error , to : "helper_error#index"
78 get :controller_helper_test , to : "controller_helper_test#index"
89
910 namespace :tests do
Original file line number Diff line number Diff line change 1+ require 'test_helper'
2+ require 'web_console/extensions'
3+
4+ module ActionDispatch
5+ class DebugExceptionsTest < ActionDispatch ::IntegrationTest
6+ class Application
7+ def call ( env )
8+ ActionView ::Base . new . render ( inline : '<% @ivar = 42 %> <%= nil.raise %></h1' )
9+ end
10+ end
11+
12+ setup do
13+ Request . stubs ( :whitelisted_ips ) . returns ( IPAddr . new ( '0.0.0.0/0' ) )
14+
15+ @app = DebugExceptions . new ( Application . new )
16+ end
17+
18+ test "follows ActionView::Template::Error original error in env['web_console.exception']" do
19+ get "/" , { } , {
20+ 'action_dispatch.show_detailed_exceptions' => true ,
21+ 'action_dispatch.show_exceptions' => true ,
22+ 'action_dispatch.logger' => Logger . new ( StringIO . new )
23+ }
24+
25+ assert_equal 42 , request . env [ 'web_console.exception' ] . bindings . first . eval ( '@ivar' )
26+ end
27+ end
28+ end
You can’t perform that action at this time.
0 commit comments