Sha256: 0171aef3188e0e42c4ab13f81bcc8cd1bcfe571fd94af31c429876c2acb99d9d

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

module Kernel
  module_function

  # Instructs Web Console to render a console in the specified binding.
  #
  # If +bidning+ isn't explicitly given it will default to the binding of the
  # previous frame. E.g. the one that invoked +console+.
  #
  # Raises DoubleRenderError if a double +console+ invocation per request is
  # detected.
  def console(binding = WebConsole.caller_bindings.first)
    raise WebConsole::DoubleRenderError if Thread.current[:__web_console_binding]

    Thread.current[:__web_console_binding] = binding

    # Make sure nothing is rendered from the view helper. Otherwise
    # you're gonna see unexpected #<Binding:0x007fee4302b078> in the
    # templates.
    nil
  end
end

module ActionDispatch
  class DebugExceptions
    def render_exception_with_web_console(request, exception)
      render_exception_without_web_console(request, exception).tap do
        # Retain superficial Rails 4.2 compatibility.
        env = Hash === request ? request : request.env

        backtrace_cleaner = env['action_dispatch.backtrace_cleaner']
        error = ExceptionWrapper.new(backtrace_cleaner, exception).exception

        # Get the original exception if ExceptionWrapper decides to follow it.
        Thread.current[:__web_console_exception] = error

        # ActionView::Template::Error bypass ExceptionWrapper original
        # exception following. The backtrace in the view is generated from
        # reaching out to original_exception in the view.
        if error.is_a?(ActionView::Template::Error)
          Thread.current[:__web_console_exception] = error.cause
        end
      end
    end

    alias_method :render_exception_without_web_console, :render_exception
    alias_method :render_exception, :render_exception_with_web_console
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
web-console-3.3.0 lib/web_console/extensions.rb
web-console-3.2.1 lib/web_console/extensions.rb
web-console-3.2.0 lib/web_console/extensions.rb
web-console-3.1.1 lib/web_console/extensions.rb