Intermittent "plugin not found" error

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. Right now, this requires the end user to manually paste the device key from the app into a custom field on the Notifications Preferences 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.

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.

2 Likes

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

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.

1 Like

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…

1 Like

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

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.

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

1 Like

Glad that worked!

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