Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next alias crashing #992

Open
glaucocustodio opened this issue Aug 21, 2024 · 1 comment
Open

next alias crashing #992

glaucocustodio opened this issue Aug 21, 2024 · 1 comment

Comments

@glaucocustodio
Copy link

glaucocustodio commented Aug 21, 2024

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
@tompng
Copy link
Member

tompng commented Sep 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants