Closed rgaufman closed 2 months ago
Also seeing this exact error and unable to start server.
chruby, ruby 3.2.3, OSX-intel ruby-lsp 0.16.2
Following - I am getting an identical error with ruby-lsp 0.16.2
on Apple Silicon / ruby 3.2.3
Thank you for the bug report. When does this happen? Is it in case you have files opened in the editor that no longer exist? Or is it when you open any file? What steps do you take to reproduce this?
I'm not 100% sure, I'm just constantly nagged by Visual Studio with this exception seemingly at random but it seems just adding simple nil handling there should fix it :)
@rgaufman could you try enable logging as described here. That should help us understand which request is causing this.
I've uninstalled the Ruby LSP extension temporarily as it was nagging me constantly, I'll re-install and check.
But considering we know where it is failing, there are multiple people impacted by this across platforms, and it would be quite easy to add nil handling there, any motivation not to handle nil there?
EDIT: I re-installed the extension and enabled server trace verbose, but for now not being nagged with errors, possible re-installing helped? - will keep an eye out and report back.
But considering we know where it is failing, there are multiple people impacted by this across platforms, and it would be quite easy to add nil handling there, any motivation not to handle nil there?
We need to first understand what situation causes the URI's path to be nil
. Maybe the issue is that it shouldn't be nil
and the bug is elsewhere.
Maybe this only happens for files in the untitled
URI scheme (when you open a file, but haven't saved it yet), in which case the more appropriate solution is to treat untitled
files differently than how we treat files with the file
scheme.
For the others that have replied here, are you on the latest version of both the extension and server?
I've been running into this a bunch recently as well, and definitely tend to keep a couple of untitled / working files open (as a sort of scratchpad). I am running v0.5.17 of the extension, and v0.16.2 of the ruby-lsp gem.
@agrobbin can you describe exact the steps you take to reproduce this? I'm not able to reproduce this by creating a new untitled Ruby file.
I've not done anything special or unique AFAIK. I'm running the VS Code extension and when I start it up with untitled files (some Markdown, some Ruby), I get this error. It happens on startup and quickly gives up after 5 failed attempts.
I'm having this exact problem on the latest macOS (upgraded yesterday), ruby 3.2.3. It first started with some 'ruby-lsp needs yjit support' error. When I recompiled ruby it started erroring with: .gem/ruby/3.2.3/gems/ruby-lsp-0.16.2/lib/ruby_lsp/store.rb:48:in
binread': no implicit conversion of nil into String (TypeError)`.
Thanks for all the information. The associated PR should fix this issue.
Thanks @vinistock! Will try it as soon as it's released and report back.
Just in case anyone else also has the same issue after updating ruby-lsp
to 0.16.3
through the extension, I also had to close all my open tabs and restart VSCode for the error to go away.
Thank you @vinistock for the quick fix here!
@vinistock I tested v0.16.3 in VS Code, closing all untitled files and restarting, and unfortunately am still running into it when I open a new untitled file:
2024-04-10 08:37:41.129 [info] (test-repo) /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.16.3/lib/ruby_lsp/store.rb:44:in `binread': no implicit conversion of nil into String (TypeError)
set(uri: uri, source: File.binread(path), version: 0)
^^^^
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.16.3/lib/ruby_lsp/store.rb:44:in `get'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11338/lib/types/private/methods/_methods.rb:279:in `bind_call'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11338/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.16.3/lib/ruby_lsp/base_server.rb:55:in `block (2 levels) in start'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.16.3/lib/ruby_lsp/base_server.rb:46:in `synchronize'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.16.3/lib/ruby_lsp/base_server.rb:46:in `block in start'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/language_server-protocol-3.17.0.3/lib/language_server/protocol/transport/io/reader.rb:20:in `read'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.16.3/lib/ruby_lsp/base_server.rb:39:in `start'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11338/lib/types/private/methods/_methods.rb:279:in `bind_call'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11338/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.16.3/exe/ruby-lsp:89:in `<top (required)>'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/bin/ruby-lsp:25:in `load'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/bin/ruby-lsp:25:in `<top (required)>'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/cli/exec.rb:58:in `load'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/cli/exec.rb:58:in `kernel_load'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/cli/exec.rb:23:in `run'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/cli.rb:451:in `exec'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/cli.rb:34:in `dispatch'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/cli.rb:28:in `start'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/exe/bundle:28:in `block in <top (required)>'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.5.6/exe/bundle:20:in `<top (required)>'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/bin/bundle:25:in `load'
from /Users/agrobbin/.asdf/installs/ruby/3.3.0/bin/bundle:25:in `<main>'
Oh, interesting. Do you mind adding some traces so that I can understand the sequence of LSP requests that are leading to this? After the associated PR, I can no longer reproduce this issue, so I'm having trouble understanding the root cause.
BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle open ruby-lsp
$stderr.puts("#{message[:method]} #{message.dig(:params, :textDocument, :uri)}")
$stderr.puts("#{method} #{uri}")
In essence, I'm trying to understand if, despite the mutex lock, we're still trying to process any feature requests for the untitled files before we process textDocument/didOpen
. Which then means we probably can't put text synchronization notifications into the queue and need to process them straight away.
Also replicated in 0.16.3 with extension v0.5.17
I re-opened code with the following files from the previous session:
2024-04-11 08:53:01.157 [info] (deno_ai) /Users/tgaff/.gem/ruby/3.2.3/gems/ruby-lsp-0.16.3/lib/ruby_lsp/store.rb:44:in `binread': no implicit conversion of nil into String (TypeError)
set(uri: uri, source: File.binread(path), version: 0)
^^^^
from /Users/tgaff/.gem/ruby/3.2.3/gems/ruby-lsp-0.16.3/lib/ruby_lsp/store.rb:44:in `get'
from /Users/tgaff/.gem/ruby/3.2.3/gems/sorbet-runtime-0.5.11338/lib/types/private/methods/_methods.rb:279:in `bind_call'
from /Users/tgaff/.gem/ruby/3.2.3/gems/sorbet-runtime-0.5.11338/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
from /Users/tgaff/.gem/ruby/3.2.3/gems/ruby-lsp-0.16.3/lib/ruby_lsp/base_server.rb:55:in `block (2 levels) in start'
from /Users/tgaff/.gem/ruby/3.2.3/gems/ruby-lsp-0.16.3/lib/ruby_lsp/base_server.rb:46:in `synchronize'
from /Users/tgaff/.gem/ruby/3.2.3/gems/ruby-lsp-0.16.3/lib/ruby_lsp/base_server.rb:46:in `block in start'
from /Users/tgaff/.gem/ruby/3.2.3/gems/language_server-protocol-3.17.0.3/lib/language_server/protocol/transport/io/reader.rb:20:in `read'
from /Users/tgaff/.gem/ruby/3.2.3/gems/ruby-lsp-0.16.3/lib/ruby_lsp/base_server.rb:39:in `start'
from /Users/tgaff/.gem/ruby/3.2.3/gems/sorbet-runtime-0.5.11338/lib/types/private/methods/_methods.rb:279:in `bind_call'
from /Users/tgaff/.gem/ruby/3.2.3/gems/sorbet-runtime-0.5.11338/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
from /Users/tgaff/.gem/ruby/3.2.3/gems/ruby-lsp-0.16.3/exe/ruby-lsp:89:in `<top (required)>'
from /Users/tgaff/.gem/ruby/3.2.3/bin/ruby-lsp:25:in `load'
from /Users/tgaff/.gem/ruby/3.2.3/bin/ruby-lsp:25:in `<top (required)>'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `load'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `kernel_load'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/cli/exec.rb:23:in `run'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/cli.rb:492:in `exec'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/cli.rb:34:in `dispatch'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/cli.rb:28:in `start'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.4.19/libexec/bundle:37:in `block in <top (required)>'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
from /Users/tgaff/.rubies/ruby-3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.4.19/libexec/bundle:29:in `<top (required)>'
from /Users/tgaff/.rubies/ruby-3.2.3/bin/bundle:25:in `load'
from /Users/tgaff/.rubies/ruby-3.2.3/bin/bundle:25:in `<main>'
@vinstock I added the traces you suggested and I see:
2024-04-11 09:03:00.735 [info] (deno_ai) textDocument/didOpen untitled:Untitled-1
2024-04-11 09:03:00.735 [info] (deno_ai) textDocument/diagnostic untitled:Untitled-1
1) I then closed the Untitled (and never-saved) file and restarted.
a) I did not see the error in this case.
2) Then I re-created that file (pasted same content) and restarted
a) I couldn't reproduce the error either though.
3) I then noticed the re-created version was detected as text. I changed it to ruby and restarted once more
a) the crash returned
I can confirm that (3) is also the trigger for me, with an untitled file detected as Ruby causing the failure!
Same scenario as @tgaff here -- I had some new, unsaved/untitled files open in tabs with valid ruby in them. After closing them and restarting LSP, it worked without errors.
I'm hoping the associated PR will fix it this time.
EDIT: It appears I was on Ruby LSP Extension v0.6.10, a prerelease version. Ruby LSP is 16.6. I was able to resolve the issue by switching back to Ruby LSP Extension v0.5.21.
I am on ruby-lsp 16.6 and I am still receiving this error. It seems to occur anytime I have an unsaved ruby file open
2024-05-03 08:54:45.682 [info] (comptroller) /Users/alex.stathis/.gem/ruby/3.3.0/gems/ruby-lsp-0.16.6/lib/ruby_lsp/store.rb:44:in `binread': no implicit conversion of nil into String (TypeError)
set(uri: uri, source: File.binread(path), version: 0)
^^^^
from /Users/alex.stathis/.gem/ruby/3.3.0/gems/ruby-lsp-0.16.6/lib/ruby_lsp/store.rb:44:in `get'
from /Users/alex.stathis/.gem/ruby/3.3.0/gems/ruby-lsp-0.16.6/lib/ruby_lsp/base_server.rb:55:in `block (2 levels) in start'
from /Users/alex.stathis/.gem/ruby/3.3.0/gems/ruby-lsp-0.16.6/lib/ruby_lsp/base_server.rb:46:in `synchronize'
from /Users/alex.stathis/.gem/ruby/3.3.0/gems/ruby-lsp-0.16.6/lib/ruby_lsp/base_server.rb:46:in `block in start'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/language_server-protocol-3.17.0.3/lib/language_server/protocol/transport/io/reader.rb:20:in `read'
from /Users/alex.stathis/.gem/ruby/3.3.0/gems/ruby-lsp-0.16.6/lib/ruby_lsp/base_server.rb:39:in `start'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11346/lib/types/private/methods/_methods.rb:279:in `bind_call'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11346/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
from /Users/alex.stathis/.gem/ruby/3.3.0/gems/ruby-lsp-0.16.6/exe/ruby-lsp:93:in `<top (required)>'
from /Users/alex.stathis/.gem/ruby/3.3.0/bin/ruby-lsp:25:in `load'
from /Users/alex.stathis/.gem/ruby/3.3.0/bin/ruby-lsp:25:in `<top (required)>'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/cli/exec.rb:58:in `load'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/cli/exec.rb:58:in `kernel_load'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/cli/exec.rb:23:in `run'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/cli.rb:484:in `exec'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/cli.rb:31:in `dispatch'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/cli.rb:25:in `start'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/exe/bundle:48:in `block in <top (required)>'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
from /Users/alex.stathis/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.3.7/exe/bundle:36:in `<top (required)>'
from /Users/alex.stathis/.rbenv/versions/3.3.0/bin/bundle:25:in `load'
from /Users/alex.stathis/.rbenv/versions/3.3.0/bin/bundle:25:in `<main>'
2024-05-03 08:54:45.688 [info] (comptroller) [Error - 8:54:45 AM] The Ruby LSP server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
2024-05-03 08:54:45.689 [info] (comptroller) [Error - 8:54:45 AM] Request textDocument/diagnostic failed.
2024-05-03 08:54:45.689 [info] (comptroller) TypeError: Cannot read properties of undefined (reading 'errorClass')
at ps.benchmarkMiddleware (/Users/alex.stathis/.vscode/extensions/shopify.ruby-lsp-0.6.10/out/extension.js:45:5666)
at zu.pullAsync (/Users/alex.stathis/.vscode/extensions/shopify.ruby-lsp-0.6.10/out/extension.js:39:6422)
I can reproduce easily:
Same as what @stathis-alexander mentioned
The gem version in my case is 0.17.1
(v0.7.1
vscode plugin) with 3.3.1 ruby and asdf
manager.:
/Users/avorobyov/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.17.1/lib/ruby_lsp/store.rb:44:in `binread': no implicit conversion of nil into String (TypeError)
Downgrading to v0.5.21
helped.
@vinistock , should the issue be reopened with more details given?
@peacefulseeker thank you for reporting. It's in fact a different regression and not the same issue as reported here. I opened a PR explaining and fixing it https://github.com/Shopify/ruby-lsp/pull/2124.
Description
I'm getting this in Visual Studio
ruby-lsp0.12.2 visual studio code 1.87.2
Seems need to add nil handling there?