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

i get unexpected @path error. #374

Closed
francelwebdev opened this issue Sep 28, 2021 · 8 comments
Closed

i get unexpected @path error. #374

francelwebdev opened this issue Sep 28, 2021 · 8 comments

Comments

@francelwebdev
Copy link

francelwebdev commented Sep 28, 2021

Hello, i get this error when i run rails s . I use ruby 3.0.2 and rails 7.0.0.alpha2.

francel@francel-Inspiron-N5010:~/Documents/rails_api$ rails s
/home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/path.rb:103:in to_s': unexpected @path (TypeError)
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/path.rb:103:in stability'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/path.rb:11:in stable?'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/path.rb:41:in entries_and_dirs'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/cache.rb:159:in block (2 levels) in unshift_paths_locked'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/cache.rb:155:in reverse_each'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/cache.rb:155:in block in unshift_paths_locked'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/store.rb:47:in block in transaction'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/store.rb:45:in synchronize'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/store.rb:45:in transaction'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/cache.rb:154:in unshift_paths_locked'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/cache.rb:107:in block in unshift_paths'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/cache.rb:107:in synchronize'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/cache.rb:107:in unshift_paths'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/change_observer.rb:21:in unshift'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/railties-7.0.0.alpha2/lib/rails/application.rb:339:in add_lib_to_load_path!'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/railties-7.0.0.alpha2/lib/rails/application.rb:72:in inherited'
from /home/francel/Documents/rails_api/config/application.rb:24:in module:RailsApi'
from /home/francel/Documents/rails_api/config/application.rb:22:in <main>'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in require'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in block in require_with_bootsnap_lfi'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in register'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in require_with_bootsnap_lfi'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in require'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/zeitwerk-2.5.0.beta3/lib/zeitwerk/kernel.rb:35:in require'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/railties-7.0.0.alpha2/lib/rails/commands/server/server_command.rb:137:in block in perform'
from internal:kernel:90:in tap'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/railties-7.0.0.alpha2/lib/rails/commands/server/server_command.rb:134:in perform'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in run'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in invoke_command'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in dispatch'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/railties-7.0.0.alpha2/lib/rails/command/base.rb:87:in perform'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/railties-7.0.0.alpha2/lib/rails/command.rb:48:in invoke'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/railties-7.0.0.alpha2/lib/rails/commands.rb:18:in '
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in require'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in block in require_with_bootsnap_lfi'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in register'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in require_with_bootsnap_lfi'
from /home/francel/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in require'
from bin/rails:4:in '
@casperisfine
Copy link
Contributor

Based on the backtrace, it fails on Bundler.bundle_path.to_s.

Could you run the following ?

bundle exec ruby -e 'p Bundler.bundle_path; p Bundler.bundle_path.to_s'

@casperisfine
Copy link
Contributor

casperisfine commented Sep 28, 2021

Here's where it fails in Ruby itself: https://github.com/ruby/ruby/blob/0db68f023372b634603c74fca94588b457be084c/ext/pathname/pathname.c#L80-L81

This suggest somehow a Pathname as set with an internal path that isn't a String. No idea how that can possibly happen. That's very likely a problem with your development environment and not Bootsnap itself, but I'll leave this open for a bit to see if we can get to the bottom of it.

@casperisfine
Copy link
Contributor

The underlying bug can be reproed with:

>> Pathname.new("/").tap { |p| p.instance_variable_set(:@path, nil) }.to_s
(irb):3:in `to_s': unexpected @path (TypeError)

The question being what in your environment might be doing such a thing.

@rrojan
Copy link

rrojan commented Oct 28, 2021

@casperisfine
Hey, I've been having the exact same problem while running rails new ProjectName. I'm still fairly new to Rails so I don't know how to work around it or what might be causing it. Tried reinstalling rails, also installing a different version, but it doesn't solve the problem.

Here's my output for bundle exec ruby -e 'p Bundler.bundle_path; p Bundler.bundle_path.to_s'

#<Pathname:/home/<username>/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0>
"/home/<username>/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0"

Edit: I managed to create a new project by following this workaround but I still get the same error while doing rails s now.

EDIT 2: Somehow the issue got resolved by removing all gems, installing rails (and dependencies) again and rehashing rbenv shims.

Still uses bootsnap 1.9.1 so it probably isn't an issue of bootsnap.

@Atastor
Copy link

Atastor commented Nov 2, 2021

Well, another take on this issue: My problems start much later, i.e. when trying to deploy. The following is from the Capistrano log:

00:23 deploy:assets:precompile
      01 RBENV_ROOT=/usr/local/rbenv RBENV_VERSION=3.0.2 rbenv exec bundle exec rake assets:precompile
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/3.0.0/pathname.rb:20: warning: already initialized constant Pathname::TO_PATH
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/pathname-0.2.0/lib/pathname.rb:20: warning: previous definition of TO_PATH was here
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/3.0.0/pathname.rb:22: warning: already initialized constant Pathname::SAME_PATHS
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/pathname-0.2.0/lib/pathname.rb:22: warning: previous definition of SAME_PATHS was here
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/3.0.0/pathname.rb:34: warning: already initialized constant Pathname::SEPARATOR_LIST
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/pathname-0.2.0/lib/pathname.rb:34: warning: previous definition of SEPARATOR_LIST was here
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/3.0.0/pathname.rb:35: warning: already initialized constant Pathname::SEPARATOR_PAT
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/pathname-0.2.0/lib/pathname.rb:35: warning: previous definition of SEPARATOR_PAT was here
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/3.0.0/pathname.rb:41: warning: already initialized constant Pathname::ABSOLUTE_PATH
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/pathname-0.2.0/lib/pathname.rb:41: warning: previous definition of ABSOLUTE_PATH was here
      01 rake aborted!
      01 TypeError: unexpected @path
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/path.rb:103:in `to_s'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/path.rb:103:in `stability'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/path.rb:11:in `stable?'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/path.rb:41:in `entries_and_dirs'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/cache.rb:159:in `block (2 levels) in unshift_paths_locked'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/cache.rb:155:in `reverse_each'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/cache.rb:155:in `block in unshift_paths_locked'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/store.rb:47:in `block in transaction'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/store.rb:45:in `synchronize'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/store.rb:45:in `transaction'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/cache.rb:154:in `unshift_paths_locked'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/cache.rb:107:in `block in unshift_paths'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/cache.rb:107:in `synchronize'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/cache.rb:107:in `unshift_paths'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/change_observer.rb:21:in `unshift'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/application.rb:361:in `add_lib_to_load_path!'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/railties-6.1.4.1/lib/rails/application.rb:95:in `inherited'
      01 /var/rails/<my-project>/releases/20211102091423/config/application.rb:11:in `<module:DSGVOAbrechnungen>'
      01 /var/rails/<my-project>/releases/20211102091423/config/application.rb:9:in `<top (required)>'
      01 /var/rails/<my-project>/releases/20211102091423/Rakefile:4:in `require_relative'
      01 /var/rails/<my-project>/releases/20211102091423/Rakefile:4:in `<top (required)>'
      01 /var/rails/<my-project>/shared/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
      01 /usr/local/rbenv/versions/3.0.2/bin/bundle:23:in `load'
      01 /usr/local/rbenv/versions/3.0.2/bin/bundle:23:in `<main>'

@casperisfine
Copy link
Contributor

      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/3.0.0/pathname.rb:20: warning: already initialized constant Pathname::TO_PATH
      01 /usr/local/rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/pathname-0.2.0/lib/pathname.rb:20: warning: previous definition of TO_PATH was here

Hum, your pathname is loaded twice because of rubygems/rubygems#4992, it could be the root cause or not. Either way I'll be closing this because I'm pretty sure it has nothing to do with bootsnap. If you want to prove it, you can set DISABLE_BOOTSNAP=1, if the still bug happens it's not a bootsnap bug.

@Atastor
Copy link

Atastor commented Nov 2, 2021

Thanks for the pointer!

@Atastor
Copy link

Atastor commented Nov 2, 2021

Just for reasons of completeness: I purged all installations of and references to pathname version 0.2 on dev and server; afterwards I was able to deploy again.

No idea, how this version had been installed in the first place; might have been a too careless gem update.

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

No branches or pull requests

4 participants