File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -342,7 +342,26 @@ 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+       invalid_paths  =  paths . reject  { |p | File . directory? ( p )  } 
347+ 
348+       if  invalid_paths . any? 
349+         Bundler . ui . warn  <<~MESSAGE 
350+           The following plugin paths don't exist: #{ invalid_paths . join ( ", " ) }  
351+ 
352+           This can happen if the plugin was installed with a different version of Ruby that has since been uninstalled. 
353+ 
354+           If you would like to reinstall the plugin, run: 
355+ 
356+           bundler plugin uninstall #{ name } #{ name }  
357+ 
358+           Continuing without installing plugin #{ name }  
359+         MESSAGE 
360+ 
361+         return 
362+       end 
363+ 
364+       Gem . add_to_load_path ( *paths ) 
346365
347366      load  path . join ( PLUGIN_FILE_NAME ) 
348367
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" ) . 
340+           and_return ( [ "invalid-file-name1" ,  "invalid-file-name2" ] ) 
341+       end 
342+ 
343+       it  "outputs a useful warning"  do 
344+         msg  = 
345+           "The following plugin paths don't exist: invalid-file-name1, invalid-file-name2.\n \n "  \
346+           "This can happen if the plugin was "  \
347+           "installed with a different version of Ruby that has since been uninstalled.\n \n "  \
348+           "If you would like to reinstall the plugin, run:\n \n "  \
349+           "bundler plugin uninstall foo-plugin && bundler plugin install foo-plugin\n \n "  \
350+           "Continuing without installing plugin foo-plugin.\n " 
351+ 
352+         expect ( Bundler . ui ) . to  receive ( :warn ) . with ( msg ) 
353+ 
354+         Plugin . hook ( Bundler ::Plugin ::Events ::EVENT1 ) 
355+ 
356+         expect ( subject . loaded? ( "foo-plugin" ) ) . to  be_falsey 
357+       end 
358+     end 
336359  end 
337360end 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments