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

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

Closed
vladimirtcats opened this issue Jan 23, 2025 · 9 comments · Fixed by #1073

Comments

@vladimirtcats
Copy link

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

tompng commented Jan 23, 2025

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

@vladimirtcats
Copy link
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

@tompng
Copy link
Member

tompng commented Jan 23, 2025

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.

@vladimirtcats
Copy link
Author

I run console in standart maOS terminal in fullscreen

@tompng
Copy link
Member

tompng commented Jan 23, 2025

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.

@vladimirtcats
Copy link
Author

vladimirtcats commented Jan 24, 2025

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| "https://github.com/#{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

@vladimirtcats
Copy link
Author

Your patch helped, thank you!

@tompng
Copy link
Member

tompng commented Jan 24, 2025

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)

@vladimirtcats
Copy link
Author

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

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

Successfully merging a pull request may close this issue.

2 participants