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

**URL:** https://meta.discourse.org/t/the-plugin-instance-find-all-method-incorrectly-treats-every-file-with-the-plugin-rb-name-as-a-discourse-plugin/54462
**Category:** Bug
**Created:** [December 19, 2016, 12:21am UTC](https://meta.discourse.org/t/the-plugin-instance-find-all-method-incorrectly-treats-every-file-with-the-plugin-rb-name-as-a-discourse-plugin/54462 "2016-12-19T00:21:09Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dmitry\_fedyuk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dmitry_fedyuk/32/293153_2.png) [@dmitry\_fedyuk](https://meta.discourse.org/u/dmitry_fedyuk)
#### Post date: [December 19, 2016, 12:21am UTC](https://meta.discourse.org/t/the-plugin-instance-find-all-method-incorrectly-treats-every-file-with-the-plugin-rb-name-as-a-discourse-plugin/54462/1 "2016-12-19T00:21:09Z")

</div>

The incorrect code:

> <https://github.com/discourse/discourse/blob/v1.7.0.beta10/lib/plugin/instance.rb#L42-L42>

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`](https://github.com/airbrake/airbrake).

If a plugin requires the `airbrake` gem, then Discourse incorrectly theats the [`lib/airbrake/delayed_job/plugin.rb`](https://github.com/airbrake/airbrake/blob/v5.6.1/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:in `module: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:in `instance\_eval’  
> from /vagrant/lib/plugin/instance.rb:312:in `activate!' from /vagrant/lib/discourse.rb:108:in `block in activate\_plugins!’  
> from /vagrant/lib/discourse.rb:105:in `each' from /vagrant/lib/discourse.rb:105:in `activate\_plugins!’  
> from /vagrant/config/application.rb:165:in `<class:Application>' from /vagrant/config/application.rb:19:in `module: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:in `require’  
> 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:in `tap’

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 19, 2016, 12:31am UTC](https://meta.discourse.org/t/the-plugin-instance-find-all-method-incorrectly-treats-every-file-with-the-plugin-rb-name-as-a-discourse-plugin/54462/2 "2016-12-19T00:31:24Z")

</div>

good point, this is a legit issue.

---

<div class="post-metadata">

### Author: ![dmitry\_fedyuk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dmitry_fedyuk/32/293153_2.png) [@dmitry\_fedyuk](https://meta.discourse.org/u/dmitry_fedyuk)
#### Post date: [December 19, 2016, 12:32am UTC](https://meta.discourse.org/t/the-plugin-instance-find-all-method-incorrectly-treats-every-file-with-the-plugin-rb-name-as-a-discourse-plugin/54462/3 "2016-12-19T00:32:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 19, 2016, 12:39am UTC](https://meta.discourse.org/t/the-plugin-instance-find-all-method-incorrectly-treats-every-file-with-the-plugin-rb-name-as-a-discourse-plugin/54462/4 "2016-12-19T00:39:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dmitry\_fedyuk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dmitry_fedyuk/32/293153_2.png) [@dmitry\_fedyuk](https://meta.discourse.org/u/dmitry_fedyuk)
#### Post date: [December 19, 2016, 5:51am UTC](https://meta.discourse.org/t/the-plugin-instance-find-all-method-incorrectly-treats-every-file-with-the-plugin-rb-name-as-a-discourse-plugin/54462/5 "2016-12-19T05:51:20Z")

</div>

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

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

```

 ![](https://global.discourse-cdn.com/meta/original/3X/7/6/760584a958cc7aefc2cd36af5f7e7299f9da0fce.png)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 16, 2017, 9:29pm UTC](https://meta.discourse.org/t/the-plugin-instance-find-all-method-incorrectly-treats-every-file-with-the-plugin-rb-name-as-a-discourse-plugin/54462/6 "2017-05-16T21:29:12Z")

</div>

Fixed per:

[https://github.com/discourse/discourse/commit/6a1f579c6e6f93579a9269acf58e7109072b943f](https://github.com/discourse/discourse/commit/6a1f579c6e6f93579a9269acf58e7109072b943f)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 16, 2017, 9:29pm UTC](https://meta.discourse.org/t/the-plugin-instance-find-all-method-incorrectly-treats-every-file-with-the-plugin-rb-name-as-a-discourse-plugin/54462/7 "2017-05-16T21:29:14Z")

</div>


