Skip to content

Commit

Permalink
Only load install error instance after requiring Bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jan 10, 2025
1 parent 6e90780 commit 7660354
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions exe/ruby-lsp-launcher
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# !!!!!!!

setup_error = nil
install_error = nil

# Read the initialize request before even starting the server. We need to do this to figure out the workspace URI.
# Editors are not required to spawn the language server process on the same directory as the workspace URI, so we need
Expand Down Expand Up @@ -45,12 +46,6 @@ rescue Errno::ECHILD
# In theory, the child process can finish before we even get to the wait call, but that is not an error
end

error_path = File.join(".ruby-lsp", "install_error")

install_error = if File.exist?(error_path)
Marshal.load(File.read(error_path))
end

begin
bundle_env_path = File.join(".ruby-lsp", "bundle_env")
# We can't require `bundler/setup` because that file prematurely exits the process if setup fails. However, we can't
Expand All @@ -67,6 +62,14 @@ begin

require "bundler"
Bundler.ui.level = :silent

# This Marshal load can only happen after requiring Bundler because it will load a custom error class from Bundler
# itself. If we try to load before requiring, the class will not be defined and loading will fail
error_path = File.join(".ruby-lsp", "install_error")
install_error = if File.exist?(error_path)
Marshal.load(File.read(error_path))
end

Bundler.setup
$stderr.puts("Composed Bundle set up successfully")
end
Expand Down

0 comments on commit 7660354

Please sign in to comment.