File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -342,7 +342,30 @@ def load_plugin(name)
342342 # done to avoid conflicts
343343 path = index . plugin_path ( name )
344344
345- Gem . add_to_load_path ( *index . load_paths ( name ) )
345+ paths = index . load_paths ( name )
346+
347+ all_paths_valid = true
348+ paths . each do |p |
349+ next if File . directory? ( p )
350+
351+ message = <<~MESSAGE
352+ Failed loading plugin #{ name } :
353+
354+ Plugin path #{ p } does not exist. This can happen if the plugin was \
355+ installed with a different version of Ruby that has since been uninstalled.
356+
357+ If you would like to reinstall the plugin, run:
358+
359+ bundler plugin uninstall #{ name } && bundler plugin install #{ name }
360+
361+ Continuing without installing plugin #{ name } .
362+ MESSAGE
363+ Bundler . ui . warn message
364+ all_paths_valid = false
365+ end
366+ return unless all_paths_valid
367+
368+ Gem . add_to_load_path ( *paths )
346369
347370 load path . join ( PLUGIN_FILE_NAME )
348371
Original file line number Diff line number Diff line change 333333 end . to output ( "win\n " ) . to_stdout
334334 end
335335 end
336+
337+ context "the plugin load_path is invalid" do
338+ before do
339+ allow ( index ) . to receive ( :load_paths ) . with ( "foo-plugin" ) . and_return ( [ "invalid-file-name" ] )
340+ end
341+
342+ it "outputs a useful warning" do
343+ msg =
344+ "Failed loading plugin foo-plugin:\n \n " \
345+ "Plugin path invalid-file-name does not exist. This can happen if the plugin was " \
346+ "installed with a different version of Ruby that has since been uninstalled.\n \n " \
347+ "If you would like to reinstall the plugin, run:\n \n " \
348+ "bundler plugin uninstall foo-plugin && bundler plugin install foo-plugin\n \n " \
349+ "Continuing without installing plugin foo-plugin.\n "
350+
351+ expect ( Bundler . ui ) . to receive ( :warn ) . with ( msg )
352+
353+ Plugin . hook ( Bundler ::Plugin ::Events ::EVENT1 )
354+
355+ expect ( subject . loaded? ( "foo-plugin" ) ) . to be_falsey
356+ end
357+ end
336358 end
337359end
You can’t perform that action at this time.
0 commit comments