Skip to content

Commit 8cb7850

Browse files
committed
Error handling
1 parent c169706 commit 8cb7850

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

lib/ruby_lsp/ruby_lsp_rails/server.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@
88

99
module RubyLsp
1010
module Rails
11+
class InvalidAddonError < RuntimeError
12+
end
13+
1114
class Server
1215
class << self
1316
def require_server_addon(gem_name)
14-
const = nil
15-
File.open("ruby-lsp-rails.txt", "a") do |f|
16-
f.puts("#{Time.now} trying to get addon...")
17-
require "ruby_lsp/#{gem_name}/addon"
18-
f.puts("#{Time.now} past require")
19-
const = Object.const_get("RubyLsp::#{gem_name.classify}::Addon") # rubocop:disable Sorbet/ConstantsFromStrings
20-
f.puts("#{Time.now} past constant ref")
21-
rescue => e
22-
# TODO: rescue constnat not exising
23-
# TODO: - show error to user if invalid name given / send back to client
24-
f.puts(e.full_message)
25-
end
26-
const
17+
require "ruby_lsp/#{gem_name}/addon"
18+
Object.const_get("RubyLsp::#{gem_name.classify}::Addon") # rubocop:disable Sorbet/ConstantsFromStrings
19+
rescue LoadError, NameError
20+
raise InvalidAddonError, "Failed to load addon '#{gem_name}'"
2721
end
2822
end
2923

0 commit comments

Comments
 (0)