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

warning: already initialized constant SSHKit::StandardError #543

Open
dorianmariecom opened this issue Sep 6, 2024 · 2 comments
Open

warning: already initialized constant SSHKit::StandardError #543

dorianmariecom opened this issue Sep 6, 2024 · 2 comments

Comments

@dorianmariecom
Copy link

it seems there is a constant being initialized twice

  There was an error while trying to load the gem 'kamal'.
  Gem Load Error is: /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/sshkit-1.23.0/lib/sshkit.rb:3: warning: already initialized constant SSHKit::StandardError

  Backtrace for gem load error is:
  /Users/dorianmariefr/src/dorianmariecom/code/spec/spec_helper.rb:5:in `warn'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/sshkit-1.23.0/lib/sshkit.rb:3:in `<module:SSHKit>'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/sshkit-1.23.0/lib/sshkit.rb:1:in `<top (required)>'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/kamal-1.8.3/lib/kamal/sshkit_with_ext.rb:1:in `<top (required)>'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/kamal-1.8.3/lib/kamal/cli/base.rb:3:in `<top (required)>'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:26:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/kamal-1.8.3/lib/kamal/cli/accessory.rb:1:in `<top (required)>'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:26:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/cref.rb:91:in `const_get'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/cref.rb:91:in `get'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:173:in `block in actual_eager_load_dir'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/helpers.rb:47:in `block in ls'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/helpers.rb:25:in `each'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/helpers.rb:25:in `ls'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:168:in `actual_eager_load_dir'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:17:in `block (2 levels) in eager_load'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:16:in `each'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:16:in `block in eager_load'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:10:in `synchronize'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:10:in `eager_load'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/kamal-1.8.3/lib/kamal.rb:12:in `<top (required)>'
  <internal:/Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
  <internal:/Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/bundler-2.5.18/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/bundler-2.5.18/lib/bundler/runtime.rb:55:in `each'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/bundler-2.5.18/lib/bundler/runtime.rb:55:in `block in require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/bundler-2.5.18/lib/bundler/runtime.rb:44:in `each'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/bundler-2.5.18/lib/bundler/runtime.rb:44:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/bundler-2.5.18/lib/bundler.rb:212:in `require'
  /Users/dorianmariefr/src/dorianmariecom/code/config/application.rb:7:in `<top (required)>'
  /Users/dorianmariefr/src/dorianmariecom/code/config/environment.rb:3:in `require_relative'
  /Users/dorianmariefr/src/dorianmariecom/code/config/environment.rb:3:in `<top (required)>'
  /Users/dorianmariefr/src/dorianmariecom/code/spec/rails_helper.rb:7:in `require_relative'
  /Users/dorianmariefr/src/dorianmariecom/code/spec/rails_helper.rb:7:in `<top (required)>'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require'
  /Users/dorianmariefr/src/dorianmariecom/code/spec/requests/pages_controllers_spec.rb:3:in `<top (required)>'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/configuration.rb:2139:in `load'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/configuration.rb:2139:in `load_file_handling_errors'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/configuration.rb:1638:in `block in load_spec_files'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/configuration.rb:1636:in `each'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/configuration.rb:1636:in `load_spec_files'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/runner.rb:102:in `setup'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/runner.rb:86:in `run'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/runner.rb:71:in `run'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/runner.rb:45:in `invoke'
  /Users/dorianmariefr/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.1/exe/rspec:4:in `<top (required)>'
  bin/rspec:31:in `load'
  bin/rspec:31:in `<main>'
@mattbrictson
Copy link
Member

AFAIK, SSHKit::StandardError is only defined by sshkit once, at lib/sshkit.rb:3:

StandardError = Class.new(::StandardError)

The only thing I can think of that would cause this error is if there is a monkey patch in another gem that is defining the SSHKit::StandardError constant before require "sshkit" is being called. Is that possible in your setup?

As a workaround/experiment, you could try adding gem "sshkit" to your Gemfile before any other gem to see if that changes the behavior at all.

@mattbrictson
Copy link
Member

mattbrictson commented Sep 6, 2024

The other thing you could try is to edit your locally installed sshkit gem (e.g. using bundle open sshkit) and add this line just before sshkit defines the SSHKit::StandardError constant in lib/sshkit.rb:

module SSHKit

  pp SSHKit.const_source_location(:StandardError) # ADD THIS LINE
  StandardError = Class.new(::StandardError)

That may provide a clue as to where the duplicate constant is being defined.

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

2 participants