irb icon indicating copy to clipboard operation
irb copied to clipboard

next alias crashing

Open glaucocustodio opened this issue 1 year ago • 1 comments

Description

I have binding.irb in a ruby file of my Rails 7.2 app.

I run a RSpec test, enter the binding session, hit n (alias of next as per my .irbrc file) and get the following error:

001> n
/Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb/context.rb:604:in `evaluate': undefined method `execute' for nil (NoMethodError)

        statement.command_class.execute(self, statement.arg)
                               ^^^^^^^^
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1049:in `block (2 levels) in eval_input'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1388:in `signal_status'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1041:in `block in eval_input'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1120:in `block in each_top_level_statement'
	from <internal:kernel>:187:in `loop'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1117:in `each_top_level_statement'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1040:in `eval_input'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1021:in `block in run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1020:in `catch'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1020:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1612:in `irb'
	from /Users/user/projects/foo/app/domains/bar/der/consumer/bla.rb:8:in `call'
	from /Users/user/projects/foo/spec/domains/bar/der/consumer/bla_spec.rb:35:in `block (5 levels) in <top (required)>'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:263:in `instance_exec'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:263:in `block in run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:511:in `block in with_around_and_singleton_context_hooks'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:468:in `block in with_around_example_hooks'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:486:in `block in run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:626:in `block in run_around_example_hooks_for'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:352:in `call'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-rails-6.1.4/lib/rspec/rails/adapters.rb:75:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:457:in `instance_exec'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:457:in `instance_exec'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:390:in `execute_with'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:352:in `call'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in `block (2 levels) in <top (required)>'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:457:in `instance_exec'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:457:in `instance_exec'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:390:in `execute_with'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:352:in `call'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:629:in `run_around_example_hooks_for'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:486:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:468:in `with_around_example_hooks'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:511:in `with_around_and_singleton_context_hooks'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:259:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:646:in `block in run_examples'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:642:in `map'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:642:in `run_examples'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:607:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:608:in `block in run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:608:in `map'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:608:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:608:in `block in run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:608:in `map'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:608:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:608:in `block in run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:608:in `map'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:608:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:121:in `map'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/configuration.rb:2091:in `with_suite_hooks'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:116:in `block in run_specs'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/reporter.rb:74:in `report'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:115:in `run_specs'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:89:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:71:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:45:in `invoke'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/exe/rspec:4:in `<top (required)>'
	from /Users/user/.asdf/installs/ruby/3.3.4/bin/rspec:25:in `load'
	from /Users/user/.asdf/installs/ruby/3.3.4/bin/rspec:25:in `<top (required)>'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/cli/exec.rb:58:in `load'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/cli/exec.rb:23:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/cli.rb:455:in `exec'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/cli.rb:35:in `dispatch'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/cli.rb:29:in `start'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/exe/bundle:28:in `block in <top (required)>'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/user/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.17/exe/bundle:20:in `<top (required)>'
	from /Users/user/.asdf/installs/ruby/3.3.4/bin/bundle:25:in `load'
	from /Users/user/.asdf/installs/ruby/3.3.4/bin/bundle:25:in `<main>'
Maybe IRB bug!

The same doesn't happen if I enter next instead 🤔

Ps: the w alias works fine

Result of irb_info

irb(main):001:0> irb_info
Ruby version: 3.3.4
IRB version: irb 1.14.0 (2024-07-06)
InputMethod: RelineInputMethod with Reline 0.5.9
Completion: Autocomplete, RegexpCompletor
.irbrc paths: /Users/user/.irbrc
RUBY_PLATFORM: arm64-darwin21
LANG env: pt_PT.UTF-8
LC_ALL env: en_US.UTF-8
East Asian Ambiguous Width: 1

Terminal Emulator

iTerm2

Setting Files

Are you using ~/.irbrc and ~/.inputrc?

# ~/.irbrc
# source: https://github.com/ruby/irb/issues/330#issuecomment-1132017233
require "reline/ansi"

if defined?(Reline::ANSI::CAPNAME_KEY_BINDINGS) # make sure you're using an affected version
  # Fix insert, delete, pgup, and pgdown.
  Reline::ANSI::CAPNAME_KEY_BINDINGS.merge!({
    "kich1" => :ed_ignore,
    "kdch1" => :key_delete,
    "kpp" => :ed_ignore,
    "knp" => :ed_ignore
  })

  Reline::ANSI.singleton_class.prepend(
    Module.new do
      def set_default_key_bindings(config)
        # Fix home and end.
        set_default_key_bindings_comprehensive_list(config)
        # Fix iTerm2 insert.
        key = [239, 157, 134]
        func = :ed_ignore
        config.add_default_key_binding_by_keymap(:emacs, key, func)
        config.add_default_key_binding_by_keymap(:vi_insert, key, func)
        config.add_default_key_binding_by_keymap(:vi_command, key, func)
        # The rest of the behavior.
        super
      end
    end
  )
end

def pbcopy(str)
  IO.popen('pbcopy', 'r+') {|io| io.puts str }
end

IRB.conf[:COMMAND_ALIASES][:w] = :whereami
IRB.conf[:COMMAND_ALIASES][:n] = :next

glaucocustodio avatar Aug 21 '24 17:08 glaucocustodio

This is because :next, :catch and :break are treated specially. Original names of these commands are :irb_break, :irb_catch and :irb_break. This will be fixed in #1004. However, I think it's better to have a warning when aliased command name does not exist.

Current workaround is to set IRB.conf[:COMMAND_ALIASES][:n] = :irb_next.

tompng avatar Sep 11 '24 12:09 tompng

I'm seeing a very similar error when trying to do IRB.conf[:COMMAND_ALIASES][:r!] = :reload!. This alias used to work as is. Not sure when it changed / started failing, and I don't know how to try with older versions since irb is now installed as a default gem (I'm on irb v1.14.3). I can open a separate issue for this if needed, but the error is the same.

pdobb avatar Jan 03 '25 15:01 pdobb

Command reload! was removed from rails in this pull request https://github.com/rails/rails/pull/53741

tompng avatar Jan 03 '25 17:01 tompng

@tompng Ok... so instead of IRB.conf[:COMMAND_ALIASES][:r!] = :reload! I can just add this to my .irbrc and it works:

def r! = reload!

Not sure how this gets registered, but I found it here:

IRB::HelperMethod.all_helper_methods_info.last
=> {display_name: :reload!, description: "Reloads the Rails application."}

Ironically, the method version of r! (in my .irbrc) is what I used to use, but it was failing in IRB so I found out how to do the command alias approach which did work. Now the opposite is true. Guess I'm not keeping up well!

Thanks for the link and nudge to try something different.

pdobb avatar Jan 03 '25 19:01 pdobb