Skip to content

An error occurred when inspecting the object: #<NoMethodError: undefined method 'end_with?' for nil> #1072

Closed

Description

@vladimirtcats

Hi everyone

When I run any command in console I get error

User.last.attributes
An error occurred when inspecting the object: #<NoMethodError: undefined method 'end_with?' for nil>
Result of Kernel#inspect: #<Hash:0x00007f05a39d7268>
=> {#<Hash:0x00007f05a39d7268>

irb_info

irb_info
Ruby version: 3.4.1
IRB version: irb 1.15.1 (2025-01-22)
InputMethod: RelineInputMethod with Reline 0.6.0 and /root/.inputrc
Completion: Tab Complete, RegexpCompletor
RUBY_PLATFORM: x86_64-linux
LANG env: C.UTF-8
LC_ALL env: C.UTF-8
East Asian Ambiguous Width: 1

Activity

  1. tompng commented on Jan 23, 2025

    @tompng
    Member

    What is the output of p STDIN.winsize, STDOUT.winsize when the error occurs?

  2. vladimirtcats commented on Jan 23, 2025

    @vladimirtcats
    Author

    What is the output of p STDIN.winsize, STDOUT.winsize when the error occurs?

    p STDIN.winsize
    [0, 0]
    An error occurred when inspecting the object: #<NoMethodError: undefined method 'end_with?' for nil>
    Result of Kernel#inspect: #<Array:0x00007f05a3ce1e90>
    => [#<Array:0x00007f05a3ce1e90>
    STDOUT.winsize
    An error occurred when inspecting the object: #<NoMethodError: undefined method 'end_with?' for nil>
    Result of Kernel#inspect: #<Array:0x00007f05a3f47d38>
    => [#<Array:0x00007f05a3f47d38>

    I use irb with rails 8

  3. tompng commented on Jan 23, 2025

    @tompng
    Member

    Thank you. I think #1073 will fix it.
    For reference, do you have any idea why winsize is [0, 0]? Terminal environment, running rails console through some command line tool etc.

  4. vladimirtcats commented on Jan 23, 2025

    @vladimirtcats
    Author

    I run console in standart maOS terminal in fullscreen

  5. tompng commented on Jan 23, 2025

    @tompng
    Member

    I can't reproduce it with the latest Rails console.
    What is the output of stty size before and after rails console?

    $ stty size
    ????
    
    $ rails console
    > p STDIN.winsize
    [0, 0] # This should be zero for this investigation
    An error occurred ...
    [#<Array ...
    > exit
    
    $ stty size
    ????
    

    If stty size is already zero, something is already going wrong. In this case, many CUI programs (ex: less, emacs, vim) does not work properly. It is better for IRB not to raise an error though.
    If STDIN.winsize is changed to zero in rails console, I think there is a library listed in your Gemfile.lock that has a bug handling winsize. Reporting it to that library will be helpful.
    In any case, resizing terminal window will restore wrong winsize to the correct value.

  6. vladimirtcats commented on Jan 24, 2025

    @vladimirtcats
    Author
    stty size
    0 0
    bundle exec rails c
    p STDIN.winsize
    [0, 0]
    An error occurred when inspecting the object: #<NoMethodError: undefined method 'end_with?' for nil>
    Result of Kernel#inspect: #<Array:0x00007f2a7b5e2d68>
    => [#<Array:0x00007f2a7b5e2d68>
    stty size
    0 0

    Gemfile:

    source 'https://rubygems.org'
    git_source(:github) { |repo| "/#{repo}.git" }
    
    ruby '3.4.1'
    
    gem 'rails', '~> 8.0', '>= 8.0.1'
    gem 'puma', '~> 6.5'
    gem 'jbuilder', '~> 2.13'
    
    gem 'pg', '~> 1.5', '>= 1.5.9'
    gem 'oj', '3.16'
    
    gem 'rack-cors', require: 'rack/cors'
    gem 'elastic-apm', '~> 4.7'
    gem 'lograge'
    
    gem 'daemons'
    gem 'sentry-raven'
    gem 'concurrent-ruby'
    
    gem 'bullet', '~> 8.0'
    
    # remove warnings
    gem 'mutex_m'
    gem 'drb'
    gem 'logger'
    gem 'ostruct'
    gem 'benchmark'
    gem 'reline'
    gem 'irb'
    
    group :development, :test do
      gem 'bundler-audit', '~> 0.9.2'
      gem 'brakeman', require: false
      gem 'pry-byebug'
      gem 'rspec-rails', '~> 7.0.0'
      gem 'rails-controller-testing'
      gem 'simplecov', require: false
      gem 'factory_bot_rails', '~> 6.4'
    end
    
    group :test do
      gem 'webmock', '~> 3.24'
      gem 'rspec_junit_formatter'
      gem 'timecop'
      gem 'database_cleaner-active_record'
      gem 'rspec_api_documentation'
      gem 'n_plus_one_control', '~> 0.7.2'
    end

    It is strange, it works good in my local envronment

    stty size
    46 156

    but it does not work in container because

    stty size
    0 0
  7. vladimirtcats commented on Jan 24, 2025

    @vladimirtcats
    Author

    Your patch helped, thank you!

  8. tompng commented on Jan 24, 2025

    @tompng
    Member

    I think something is wrong with your container launching/connecting command or its command alias.

    Here is a zero winsize reproduction example. Running docker with -t option (allocating a pseudo-TTY) but STDOUT is connected to a pipe to cat, so the correct winsize is unavailable.

    $ docker run --rm -it rubylang/rubyfarm | cat
    root@79ddcce38253:/# stty size
    0 0
    root@79ddcce38253:/# ruby -e "puts(*1..100)" | less
    Gets corrupt screen while scrolling up and down (if the actual winsize is not 80x24)
    
  9. vladimirtcats commented on Jan 27, 2025

    @vladimirtcats
    Author

    @tompng Unfortunately, I can not influence parameters of container. Could you merge your patch in master?

  10. klausmeyer commented on Mar 18, 2025

    @klausmeyer

    Also running into this issue - maybe one interesting observation:

    I'm only getting the error when I access the container shell via Kubernetes Dashboard (Web UI) and not when using kubectl or other CLI based tools like k9s.

    Here is the output of the stty command each:

    Kubernetes Dashboard:

    ~ $ stty size
    stty: standard input
    

    CLI:

    ~ $ stty size
    80 174
    
  11. Napolskih commented on Apr 2, 2025

    @Napolskih

    @tompng

    I also encountered this problem in containers running in Kubernetes, when accessing via a web terminal.

    There is no problem locally, even in containers (not in Kubernetes).

    It was noticed that the problem is related to updating gems:
    async-http
    traces
    console

    It seems that the problem appears if you update the console gem above 1.29.2.

    Image
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb/pager.rb:192:in `write'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/prettyprint-0.2.0/lib/prettyprint.rb:184:in `text'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb/color_printer.rb:50:in `text'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/pp-0.6.2/lib/pp.rb:206:in `rescue in block in pp'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/pp-0.6.2/lib/pp.rb:204:in `block in pp'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/prettyprint-0.2.0/lib/prettyprint.rb:255:in `block (2 levels) in group'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/prettyprint-0.2.0/lib/prettyprint.rb:282:in `nest'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/prettyprint-0.2.0/lib/prettyprint.rb:254:in `block in group'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/prettyprint-0.2.0/lib/prettyprint.rb:267:in `group_sub'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/prettyprint-0.2.0/lib/prettyprint.rb:253:in `group'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/pp-0.6.2/lib/pp.rb:203:in `pp'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb/color_printer.rb:35:in `pp'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb/color_printer.rb:10:in `block in pp'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/pp-0.6.2/lib/pp.rb:160:in `guard_inspect_key'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb/color_printer.rb:10:in `pp'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb/inspector.rb:122:in `block in <module:IRB>'
    (app):3:in `inspect_value'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb/context.rb:662:in `inspect_last_value'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:542:in `block in output_value'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb/pager.rb:66:in `page_with_preview'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:541:in `output_value'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:209:in `block (2 levels) in eval_input'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:512:in `signal_status'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:193:in `block in eval_input'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:272:in `block in each_top_level_statement'
    <internal:kernel>:187:in `loop'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:269:in `each_top_level_statement'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:192:in `eval_input'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:173:in `block in run'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:172:in `catch'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/irb-1.15.1/lib/irb.rb:172:in `run'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/commands/console/irb_console.rb:129:in `start'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/commands/console/console_command.rb:59:in `start'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/commands/console/console_command.rb:8:in `start'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/commands/console/console_command.rb:87:in `perform'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/thor-1.3.2/lib/thor/command.rb:28:in `run'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/command/base.rb:178:in `invoke_command'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/thor-1.3.2/lib/thor.rb:538:in `dispatch'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/command/base.rb:73:in `perform'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/command.rb:71:in `block in invoke'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/command.rb:149:in `with_argv'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/command.rb:69:in `invoke'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/railties-7.2.2.1/lib/rails/commands.rb:18:in `<main>'
    /usr/local/lib/ruby/3.3.0/bundled_gems.rb:69:in `require'
    /usr/local/lib/ruby/3.3.0/bundled_gems.rb:69:in `block (2 levels) in replace_require'
    /usr/src/app/vendor/cache/ruby/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    bin/rails:6:in `<main>'
    

    Please release fixed version.

  12. tompng commented on Apr 3, 2025

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions