Pry Remote / ByeBug next goes into Teardown

假装没事ソ 提交于 2019-12-12 03:18:49

问题


So I've decided to split my last post since the bug is Related to ByeBug more than to Pry-Remote (I think). Last post URL: Pry-Remote not triggered Rails 4

Problem:

When typing Next in Pry-Remote, ByeBug acts unexpectedly and goes to "teardown".

Also created an ByeBug Issue: https://github.com/deivid-rodriguez/pry-byebug/issues/78

What I am running:

  gem 'pry-byebug', '=1.3.3'
  gem 'pry-stack_explorer'
  gem 'pry-rails'
  gem 'pry-remote'

pry (0.10.2)
  coderay (~> 1.1.0)
  method_source (~> 0.8.1)
  slop (~> 3.4)
pry-byebug (1.3.3)
  byebug (~> 2.7)
  pry (~> 0.10)
pry-rails (0.3.4)
  pry (>= 0.9.10)
pry-remote (0.1.8)
  pry (~> 0.9)
  slop (~> 3.0)
pry-stack_explorer (0.4.9.2)
  binding_of_caller (>= 0.7)
  pry (>= 0.9.11)

ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
Rails 4.2.4

Note 1:

Updated all the pry related gems

https://gist.github.com/YOUConsulting/65cdcdc22d32780dde51


回答1:


You seem to be using an ancient version of pry-byebug, the latest as of this writing is 3.2.0 but you're using 1.3.3. If you update your gems there's a good chance the problem will go away.

UPDATE

After further research it looks like pry-remote and pry-byebug do not work well together on Ruby 2.x.

However, there is a bit of code a coder posted, most of the comments are in Japanese, but they claim it makes pry-remote work. I'm including their code below (I've translated the Japanese as well):

module ObjectUtils

  # remote parameter is the ip address, default port is 9876
  def pry!(remote=nil, port=9876)
    $LOAD_PATH.unshift "#{ENV['RUBY_PATH']}/debuger"
    require 'pry'
    return if __callee__ == :pry1 and !Pry.instance_variable_get(:@pry_is_start)

    Pry.instance_variable_set(:@pry_is_start, true)

    # if defined? Pry and defined? PryStackExplorer and Pry.config.hooks.hook_exists? :after_session, :delete_frame_manager
    #   Pry.config.hooks.delete_hook :when_started, :save_caller_bindings
    #   Pry.config.hooks.delete_hook :after_session, :delete_frame_manager
    # end
    if remote or ENV['USE_PRY_REMOTE']
      if defined? PryNav
        if defined? ActionDispatch # rails application.
          if Pry.initial_session?
            warn '[0m[33mloading pry remote ...[0m'
            binding.of_caller(1).remote_pry(remote, port)
          end
        else
          binding.of_caller(1).remote_pry(remote, port)
        end
      else
        require_remote_debugger
        binding.of_caller(1).remote_pry(remote, port)
        `notify-send -t 5000 -- "exiting pry remote ..."` if find_executable 'notify-send'
      end
    else
      # if these constants are defined then you're already in a debugger session
      if defined? PryByebug or defined? PryDebugger or defined? PryNav
        if defined? ActionDispatch # rails application.
          if Pry.initial_session?
            # When sending a new request, it will reset Pry.initial_sesssion? It is true.
            # This ensures that, in the same request the debugger will be activated once.
            # Only on the next request will it be reinitialized
            warn '[1m[33mloading debugger ...[0m'
            binding.of_caller(1).pry
          end
        else
          binding.of_caller(1).pry
        end
      else
        require_debugger
        binding.of_caller(1).pry
      end
    end
  end

  def require_debugger
    case RbConfig::CONFIG['ruby_version']
    when '2.0.0'...'3.0.0'
      require 'pry-byebug'
    when '1.9.0'...'2.0.0'
      require 'pry-debugger'
    end
    # to make sure the debugger is loaded
    warn '[1m[33mloading debugger ...[0m'
    require 'ap'; AwesomePrint.pry!
  rescue LoadError
    require 'pry-nav'
    warn '[1m[33mloading debugger ...[0m'
  end

  def require_remote_debugger
    require 'pry-remote'
    require 'pry-nav'
    warn '[0m[33mloading pry remote ...[0m'
    `notify-send -t 10000 -- "loading pry remote ..."` if system 'which notify-send &>/dev/null'
    require 'ap'; AwesomePrint.pry!
  end

end

Kernel.send(:include, ObjectUtils)
Object.send(:include, Kernel)

You'll need to call these methods, and might need to tweak them for your usage.


References

  • https://github.com/Mon-Ouie/pry-remote/issues/58
  • https://github.com/Mon-Ouie/pry-remote/issues/35#issuecomment-20290739
  • https://github.com/deivid-rodriguez/pry-byebug/issues/33
  • https://rubygems.org/gems/pry-byebug


来源:https://stackoverflow.com/questions/32883285/pry-remote-byebug-next-goes-into-teardown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!