Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion bundler/lib/bundler/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,26 @@ def load_plugin(name)
# done to avoid conflicts
path = index.plugin_path(name)

Gem.add_to_load_path(*index.load_paths(name))
paths = index.load_paths(name)
invalid_paths = paths.reject {|p| File.directory?(p) }

if invalid_paths.any?
Bundler.ui.warn <<~MESSAGE
The following plugin paths don't exist: #{invalid_paths.join(", ")}.

This can happen if the plugin was installed with a different version of Ruby that has since been uninstalled.

If you would like to reinstall the plugin, run:

bundler plugin uninstall #{name} && bundler plugin install #{name}

Continuing without installing plugin #{name}.
MESSAGE

return
end

Gem.add_to_load_path(*paths)

load path.join(PLUGIN_FILE_NAME)

Expand Down
23 changes: 23 additions & 0 deletions bundler/spec/bundler/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,28 @@
end.to output("win\n").to_stdout
end
end

context "the plugin load_path is invalid" do
before do
allow(index).to receive(:load_paths).with("foo-plugin").
and_return(["invalid-file-name1", "invalid-file-name2"])
end

it "outputs a useful warning" do
msg =
"The following plugin paths don't exist: invalid-file-name1, invalid-file-name2.\n\n" \
"This can happen if the plugin was " \
"installed with a different version of Ruby that has since been uninstalled.\n\n" \
"If you would like to reinstall the plugin, run:\n\n" \
"bundler plugin uninstall foo-plugin && bundler plugin install foo-plugin\n\n" \
"Continuing without installing plugin foo-plugin.\n"

expect(Bundler.ui).to receive(:warn).with(msg)

Plugin.hook(Bundler::Plugin::Events::EVENT1)

expect(subject.loaded?("foo-plugin")).to be_falsey
end
end
end
end