# Intermittent "plugin not found" error

**URL:** https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181
**Category:** Development
**Created:** [December 1, 2023, 11:43am UTC](https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181 "2023-12-01T11:43:46Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Judith](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/judith/32/289903_2.png) [@Judith](https://meta.discourse.org/u/Judith)
#### Post date: [December 1, 2023, 11:43am UTC](https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181/1 "2023-12-01T11:43:46Z")

</div>

I’m developing a plugin that will make it easy to connect Discourse installations to any custom app that your organisation may have and deliver push notifications through that app (mainly useful for iOS where webpush doesn’t work). The plugin repository is [GitHub - Sprachprofi/discourse-app-notifications: Send Discourse push notifications through FCM to any custom app · GitHub](https://github.com/Sprachprofi/discourse-app-notifications). Right now, this requires the end user to manually paste the device key from the app into a custom field on the [Notifications Preferences](https://meta.discourse.org/u/judith/preferences/notifications) page after logging in.

My problem is that when someone installs the app, logs in and then goes to copy-paste their device key, it doesn’t work, Discourse yields “required plugin ‘discourse\_app\_notifications’ not found” for the POST /app\_notifications/subscribe action (and same for the unsubscribe action). However, when the same person force-quits the app and then does the same step again, there is no error message and the push notifications do work.

**What could possibly cause Discourse to recognize the plugin in one case and not recognize it in the other case, when the same call is made from within the app?** No changes have been made on the Discourse installation in the meantime and this behaviour is consistent and reproducible.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [December 1, 2023, 12:03pm UTC](https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181/2 "2023-12-01T12:03:45Z")

</div>

This doesn’t necessarily solve your problem, but may cause issues and definitely makes your code harder to navigate for the uninitiated.

The structure of your plugin is very unconventional and you should consider refactoring it to match Zeitwerk standards.

I’m not sure if that will be causing any of your problems.

> [@Structuring a plugin for Rails autoloading](https://meta.discourse.org/t/structuring-a-plugin-for-rails-autoloading/256092):
>
> Many plugins include lots of class definitions inside plugin.rb, or use require\_relative to load ruby files. That works, but it comes with some disadvantages: No auto-reloading of changes in development. Any changes require a full server restart Getting the require calls in the right order can be painful If they are require’d outside the after\_initialize block, then other autoloaded classes/modules may not be available There is a solution! Plugins can lean on the standard Rails autoloading sy…

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 1, 2023, 1:38pm UTC](https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181/3 "2023-12-01T13:38:21Z")

</div>

I had a similar problem (though it seemed to be warning and not an error), but making my line like this:

> <https://github.com/Sprachprofi/discourse-app-notifications/blob/78b689cc459c1a7a26ffc9dbd951c45e12e57fcd/plugin.rb#L43>

use the `PLUGIN_NAME` seems to have fixed it.

Like Robert said, it might fix some things if you put your controller in `app/controllers` rather than in `plugin.rb`. I too was confused where it might be.

---

<div class="post-metadata">

### Author: ![Judith](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/judith/32/289903_2.png) [@Judith](https://meta.discourse.org/u/Judith)
#### Post date: [December 2, 2023, 8:47pm UTC](https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181/4 "2023-12-02T20:47:59Z")

</div>

I do have `requires_plugin DiscourseAppNotifications::PLUGIN_NAME`, so I’m not sure which change you’re suggesting, if any?

The reason the plugin is structured like this is because I used the Pushover Notifications plugin as a foundation rather than coding from scratch. It’s my first plugin and due to the interaction with the app it’s notoriously difficult to debug, so I was hoping to avoid some bugs this way…

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 3, 2023, 12:46am UTC](https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181/5 "2023-12-03T00:46:38Z")

</div>

> [@Judith](#):
>
> I’m not sure which change you’re suggesting, if any?

No. It s mostly a shrug. I had the problem, but you seem to have done what I did to fix it.

> [@Judith](#):
>
> I used the Pushover Notifications plugin as a foundation rather than coding from scratch.

Sounds like what I would have done.

Rails is really picky about a bunch of things. I didn’t know it would let you put that stuff in plugin.rb. And I don’t know if moving stuff to a bunch of different places will fix it. Sorry.

---

<div class="post-metadata">

### Author: ![Judith](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/judith/32/289903_2.png) [@Judith](https://meta.discourse.org/u/Judith)
#### Post date: [December 11, 2023, 5:40pm UTC](https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181/6 "2023-12-11T17:40:45Z")

</div>

Thank you, @pfaffman . I rewrote the plugin according to the guidelines and it’s working now!

New URL: [GitHub - Sprachprofi/discourse-fcm-notifications: Send Discourse push notifications through FCM to any custom app · GitHub](https://github.com/Sprachprofi/discourse-fcm-notifications)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 12, 2023, 11:17am UTC](https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181/7 "2023-12-12T11:17:22Z")

</div>

Glad that worked!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [January 11, 2024, 11:17am UTC](https://meta.discourse.org/t/intermittent-plugin-not-found-error/287181/8 "2024-01-11T11:17:51Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
