Skip to content

Exception when using irb:rdbg where objectto_s might return nil #1089

Closed

Description

@adam12

The to_s method returning nil is obviously an issue, but we should guard against that anyways.

# test.rb
class SomeObject
  def to_s
    nil
  end

  def do_something
    debugger
  end
end

SomeObject.new.do_something
$ rdbg -e 'config set irb_console 1 ;; c' -c ruby test.rb
/Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:601:in 'IRB::Irb#truncate_prompt_main': undefined method 'tr' for nil (NoMethodError)

      str = str.tr(CONTROL_CHARACTERS_PATTERN, ' ')
               ^^^
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:616:in 'block in IRB::Irb#format_prompt'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:610:in 'String#gsub'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:610:in 'IRB::Irb#format_prompt'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:585:in 'IRB::Irb#generate_prompt'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:242:in 'IRB::Irb#readmultiline'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:270:in 'block in IRB::Irb#each_top_level_statement'
        from <internal:kernel>:168:in 'Kernel#loop'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:269:in 'IRB::Irb#each_top_level_statement'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:192:in 'IRB::Irb#eval_input'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:130:in 'block in IRB::Irb#debug_readline'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:123:in 'Kernel#catch'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb.rb:123:in 'IRB::Irb#debug_readline'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb/debug/ui.rb:57:in 'block in IRB::Debug::UI#readline'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb/debug/ui.rb:76:in 'block in IRB::Debug::UI#setup_interrupt'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/session.rb:1989:in 'DEBUGGER__::Session#intercept_trap_sigint'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb/debug/ui.rb:69:in 'IRB::Debug::UI#setup_interrupt'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/irb-1.15.2/lib/irb/debug/ui.rb:55:in 'IRB::Debug::UI#readline'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/session.rb:445:in 'DEBUGGER__::Session#wait_command'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/session.rb:405:in 'block in DEBUGGER__::Session#wait_command_loop'
        from <internal:kernel>:168:in 'Kernel#loop'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/session.rb:404:in 'DEBUGGER__::Session#wait_command_loop'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/session.rb:330:in 'DEBUGGER__::Session#process_event'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/session.rb:255:in 'DEBUGGER__::Session#session_server_main'
        from /Users/adam/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/debug-1.10.0/lib/debug/session.rb:207:in 'block in DEBUGGER__::Session#activate'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions