The Plugin::Instance.find_all method incorrectly treats every file with the «plugin.rb» name as a Discourse plugin


(Discourse.PRO) #1

The incorrect code:

It will fail if a plugin requires a gem, which contain a file with the plugin.rb name.
An example of problem gem is airbrake.

If a plugin requires the airbrake gem, then Discourse incorrectly theats the lib/airbrake/delayed_job/plugin.rb file as a Discourse plugin, and fails with the message:

/vagrant/plugins/df-core/gems/2.3.1/gems/airbrake-5.6.1/lib/airbrake/delayed_job/plugin.rb:6:in <module:Plugins>': uninitialized constant Delayed (NameError) from /vagrant/plugins/df-core/gems/2.3.1/gems/airbrake-5.6.1/lib/airbrake/delayed_job/plugin.rb:2:inmodule:Delayed
from /vagrant/plugins/df-core/gems/2.3.1/gems/airbrake-5.6.1/lib/airbrake/delayed_job/plugin.rb:1:in activate!' from /vagrant/lib/plugin/instance.rb:312:ininstance_eval’
from /vagrant/lib/plugin/instance.rb:312:in activate!' from /vagrant/lib/discourse.rb:108:inblock in activate_plugins!'
from /vagrant/lib/discourse.rb:105:in each' from /vagrant/lib/discourse.rb:105:inactivate_plugins!‘
from /vagrant/config/application.rb:165:in <class:Application>' from /vagrant/config/application.rb:19:inmodule:Discourse
from /vagrant/config/application.rb:18:in <top (required)>' from /home/vagrant/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:78:inrequire’
from /home/vagrant/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:78:in block in server' from /home/vagrant/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:75:intap’


(Sam Saffron) #2

good point, this is a legit issue.


(Discourse.PRO) #3

Moreover, looks like the buggy code is also unefficient, because it searches for the «plugin.rb» files in all the filesystem tree inside the «plugins» directory, despite the Discourse’s «plugin.rb» files are always on the second level in this tree.


(Sam Saffron) #4

btw. PR totally welcome to fix this, should be simple.


(Discourse.PRO) #5

As I have checked in the Ruby debugger, the following code works correctly for both the real directories and symlinks:

Dir["#{parent_path}/*/plugin.rb"].sort.each do |path|


(Sam Saffron) #6

Fixed per:


(Sam Saffron) #7