tapioca icon indicating copy to clipboard operation
tapioca copied to clipboard

Error init tapioca with ruby 3.4

Open ricsdeol opened this issue 11 months ago • 13 comments

Hi I'm having this error initializing Tapioca with command:

bundle exec tapioca init

Error:

➜ bundle exec tapioca init
   identical  sorbet/config
   identical  sorbet/tapioca/config.yml
   identical  sorbet/tapioca/require.rb
       force  bin/tapioca
Retrieving index from central repository... bundler: failed to load command: tapioca (/home/ricsdeol/.asdf/installs/ruby/3.4.1/bin/tapioca)
/home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:46:in 'OpenSSL::SSL::SSLSocket#connect_nonblock': SSL_connect returned=1 errno=0 peeraddr=[2606:50c0:8000::154]:443 state=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError)
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:46:in 'Net::Protocol#ssl_socket_connect'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/3.4.0/net/http.rb:1736:in 'Net::HTTP#connect'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/3.4.0/net/http.rb:1636:in 'Net::HTTP#do_start'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/3.4.0/net/http.rb:1625:in 'Net::HTTP#start'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/3.4.0/net/http.rb:1064:in 'Net::HTTP.start'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/commands/annotations.rb:180:in 'Tapioca::Commands::Annotations#fetch_http_file'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'UnboundMethod#bind_call'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'block in Tapioca::Commands::Annotations#_on_method_added'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/commands/annotations.rb:158:in 'Tapioca::Commands::Annotations#fetch_file'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'UnboundMethod#bind_call'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'block in Tapioca::Commands::Annotations#_on_method_added'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/commands/annotations.rb:104:in 'Tapioca::Commands::Annotations#fetch_index'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'UnboundMethod#bind_call'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'block in Tapioca::Commands::Annotations#_on_method_added'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/commands/annotations.rb:87:in 'block in Tapioca::Commands::Annotations#fetch_indexes'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/commands/annotations.rb:86:in 'Array#each'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/commands/annotations.rb:86:in 'Tapioca::Commands::Annotations#fetch_indexes'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'UnboundMethod#bind_call'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'block in Tapioca::Commands::Annotations#_on_method_added'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/commands/annotations.rb:40:in 'Tapioca::Commands::Annotations#execute'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'UnboundMethod#bind_call'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'block in Tapioca::Commands::Annotations#_on_method_added'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/commands/command.rb:27:in 'block in Tapioca::Commands::Command#run'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca.rb:24:in 'block in Tapioca.silence_warnings'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/user_interaction.rb:46:in 'Gem::DefaultUserInteraction.use_ui'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca.rb:23:in 'Tapioca.silence_warnings'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/commands/command.rb:26:in 'Tapioca::Commands::Command#run'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/cli.rb:371:in 'Tapioca::Cli#annotations'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/command.rb:28:in 'Thor::Command#run'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'Thor::Invocation#invoke_command'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor.rb:538:in 'Thor.dispatch'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:116:in 'Thor::Invocation#invoke'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/cli.rb:31:in 'block in Tapioca::Cli#init'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/runtime/trackers.rb:26:in 'Tapioca::Runtime::Trackers.with_trackers_enabled'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'UnboundMethod#bind_call'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11765/lib/types/private/methods/_methods.rb:279:in 'block in Tapioca::Runtime::Trackers._on_method_added'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/lib/tapioca/cli.rb:29:in 'Tapioca::Cli#init'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/command.rb:28:in 'Thor::Command#run'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'Thor::Invocation#invoke_command'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor.rb:538:in 'Thor.dispatch'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/base.rb:584:in 'Thor::Base::ClassMethods#start'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/tapioca-0.16.8/exe/tapioca:30:in '<top (required)>'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/bin/tapioca:25:in 'Kernel#load'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/bin/tapioca:25:in '<top (required)>'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/cli/exec.rb:59:in 'Kernel.load'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/cli/exec.rb:59:in 'Bundler::CLI::Exec#kernel_load'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/cli/exec.rb:23:in 'Bundler::CLI::Exec#run'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/cli.rb:452:in 'Bundler::CLI#exec'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/vendor/thor/lib/thor/command.rb:28:in 'Bundler::Thor::Command#run'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in 'Bundler::Thor::Invocation#invoke_command'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/vendor/thor/lib/thor.rb:538:in 'Bundler::Thor.dispatch'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/cli.rb:35:in 'Bundler::CLI.dispatch'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/vendor/thor/lib/thor/base.rb:584:in 'Bundler::Thor::Base::ClassMethods#start'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/cli.rb:29:in 'Bundler::CLI.start'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/exe/bundle:28:in 'block in <top (required)>'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/bundler/friendly_errors.rb:117:in 'Bundler.with_friendly_errors'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/exe/bundle:20:in '<top (required)>'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/bin/bundle:25:in 'Kernel#load'
        from /home/ricsdeol/.asdf/installs/ruby/3.4.1/bin/bundle:25:in '<main>'

Ruby version: 3.4.1p0

Tapioca version: tapioca (0.16.8)

I'm using Ubuntu 22.04, is there a library I should install to make it work?

Thank in advance for the help

ricsdeol avatar Jan 18 '25 20:01 ricsdeol

Looking at the stack trace I think you have a require call in require.rb that triggers Net::HTTP.start. Try to clean up that file (most entries are probably unnecessary).

KaanOzkan avatar Jan 20 '25 15:01 KaanOzkan

Facing the same issue. Happens even with a clean require.rb, and even if the entire sorbet directory is deleted.

$ ruby -v
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]

KarimElsayad247 avatar Mar 15 '25 23:03 KarimElsayad247

I removed everything sorbet, tried to add it again, and got the same error.

✗❯ bundle exec tapioca init
   identical  sorbet/config
   identical  sorbet/tapioca/config.yml
   identical  sorbet/tapioca/require.rb
       force  bin/tapioca
Retrieving index from central repository... bundler: failed to load command: tapioca (/home/karim/.rbenv/versions/3.4.2/bin/tapioca)
/home/karim/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:46:in 'OpenSSL::SSL::SSLSocket#connect_nonblock': SSL_connect returned=1 errno=0 peeraddr=185.199.111.133:443 stat
e=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError)
        from /home/karim/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:46:in 'Net::Protocol#ssl_socket_connect'
        from /home/karim/.rbenv/versions/3.4.2/lib/ruby/3.4.0/net/http.rb:1736:in 'Net::HTTP#connect'
        from /home/karim/.rbenv/versions/3.4.2/lib/ruby/3.4.0/net/http.rb:1636:in 'Net::HTTP#do_start'
        from /home/karim/.rbenv/versions/3.4.2/lib/ruby/3.4.0/net/http.rb:1625:in 'Net::HTTP#start'
        from /home/karim/.rbenv/versions/3.4.2/lib/ruby/3.4.0/net/http.rb:1064:in 'Net::HTTP.start'
        from /home/karim/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/tapioca-0.16.11/lib/tapioca/commands/annotations.rb:180:in 'Tapioca::Commands::Annotations#fetch_http_file'

some manual putting reveals the target uri of the request is

https://raw.githubusercontent.com/Shopify/rbi-central/main/index.json

which opens ok in my browser.

c_rehash, update-ca-certificates -v, force-updating ca-certificates, all those shenanigans didn't help

KarimElsayad247 avatar Mar 16 '25 04:03 KarimElsayad247

Thanks, this looks like there's a missing local certificate. I assume in a standalone script that does https://github.com/Shopify/tapioca/blob/3008dfee2bf44483ff4fecfcd2410cf3a4062bde/lib/tapioca/commands/annotations.rb#L180-L182 with the uri created from https://raw.githubusercontent.com/Shopify/rbi-central/main/index.json you'll also run into the error.

KaanOzkan avatar Mar 18 '25 14:03 KaanOzkan

@ricsdeol or @KarimElsayad247, is your internet connection going through a proxy server?

andyw8 avatar Mar 18 '25 15:03 andyw8

@andyw8 Non of which that I'm aware. No vpns either.

That said, the URL fetches a document without problems in my browser (firefox) so I think the problem being my connection is unlikely.

Could it be that Tapioca tries to install its own certificates? or Ruby tries to install its certificates, but fails?

KarimElsayad247 avatar Mar 20 '25 00:03 KarimElsayad247

So I just tried this so-called ruby SSL checker

https://github.com/rubygems/ruby-ssl-check/tree/master

and it seems I have a problems connecting with rubygems...

Trying connections to https://rubygems.org:

Bundler:       ✅ success
RubyGems:      ✅ success
Ruby net/http: ❌ failed

Unfortunately, this Ruby can't connect to rubygems.org. 😡

Below affect only Ruby net/http connections:

SSL_CERT_FILE: ❌ is missing /etc/ssl/certs/ca-certificates.crt
SSL_CERT_DIR:  ✅ exists     /home/karim/.rbenv/versions/3.4.2/openssl/ssl/certs


Your Ruby can't connect to rubygems.org because you are missing the certificate
files OpenSSL needs to verify you are connecting to the genuine rubygems.org servers.

KarimElsayad247 avatar Mar 20 '25 00:03 KarimElsayad247

Yes, it looks like a problem with your Ruby installation.

andyw8 avatar Mar 20 '25 00:03 andyw8

However... I'm pretty sure I can connect to rubygems, judging by the fact I can successfully run gem update --system and bundle install

KarimElsayad247 avatar Mar 20 '25 00:03 KarimElsayad247

Is it just luck that the problem only manifested with tapioca init?

KarimElsayad247 avatar Mar 20 '25 00:03 KarimElsayad247

I created an issue in RubyGems repo with as much details as I could about this issue

https://github.com/rubygems/rubygems/issues/8578

KarimElsayad247 avatar Mar 20 '25 02:03 KarimElsayad247

So I finally figured it out

Turns out, my problem was that default OpenSSL cert file used a path relative to my home dir like this

"~/.rbenv/versions/3.4.2/openssl/ssl/cert.pem"

but when I set my SSL_CERT_FILE env var to an absolute path like this

export SSL_CERT_FILE=/home/karim/.rbenv/versions/3.4.2/openssl/ssl/cert.pem

The cert was finally found.

I also discovered that Ruby's File.exist? doesn't seem to understand ~, as it always returned false, this is why the SSL check script always failed.

KarimElsayad247 avatar Mar 26 '25 13:03 KarimElsayad247

Had the same issue and that led me to read these related issues: https://github.com/ruby/rubygems/issues/8578, https://github.com/ruby/net-http/issues/229, https://github.com/ruby/openssl/issues/949.

In my case, adding

gem "openssl", "~> 3.3.1"

to my Gemfile and running bundle fixed the issue.

marcw avatar Dec 03 '25 08:12 marcw