errbotio / errbot

Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
http://errbot.io
GNU General Public License v3.0
3.13k stars 615 forks source link

Blacklisted plugins causes AttributeError on startup #1368

Closed gaggle closed 4 years ago

gaggle commented 5 years ago

In order to let us help you better, please fill out the following fields as best you can:

I am...

I am running...

Issue description

Blacklisting plugins results in exceptions during bot startup, the exception is highly visible in bot log output and the error is emitted by the bot in Slack which is highly confusing.

The exception is: .../lib/python3.6/site-packages/errbot/plugin_manager.py:

                if self.is_plugin_blacklisted(name):
                    errors += f'Notice: {plugin.name} is blacklisted, ' \
                              f'use {self.bot.prefix}plugin unblacklist {name} to unblacklist it.\n'
                    continue

But there is no self.bot, so self.bot.prefix throws exception, which causes the bot to emit errors.

Quick glance at git history looks to me like this was introduced May 28th, 2018 in commit 21c282356892596cf18b356cfe2435c4abe41b70 where self.bot property was removed from plugin_manager.py (L140) as part of "removed circular dependency between pm and errbot "

Steps to reproduce

  1. Create backup.py with content:
    
    ## This file is not executable on its own. use errbot -r FILE to restore your bot.

bot.plugin_manager["configs"] = {} bot.plugin_manager["bl_plugins"] = ['Flows'] if "installed_repos" in bot.repo_manager: for repo in bot.repo_manager["installed_repos"]: log.error(bot.repo_manager.install_repo(repo)) log.info("Restoring plugins data.") bot.plugin_manager.update_plugin_places(bot.repo_manager.get_all_repos_paths()) pobj = bot.plugin_manager.plugins["Example"] pobj.init_storage() pobj.close_storage() pobj = bot.plugin_manager.plugins["Plugins"] pobj.init_storage() pobj.close_storage() pobj = bot.plugin_manager.plugins["CommandNotFoundFilter"] pobj.init_storage() pobj.close_storage() pobj = bot.plugin_manager.plugins["Help"] pobj.init_storage() pobj.close_storage() pobj = bot.plugin_manager.plugins["Backup"] pobj.init_storage() pobj.close_storage() pobj = bot.plugin_manager.plugins["ACLs"] pobj.init_storage() pobj.close_storage() pobj = bot.plugin_manager.plugins["VersionChecker"] pobj.init_storage() pobj.close_storage()


2. Run `errbot -r backup.py`

3. Run `errbot`

Observe error in log output:

11:00:29 ERROR errbot.plugin_manager Error loading Flows. Traceback (most recent call last): File "/home/jln/.virtualenvs/slack-jokebot/lib/python3.6/site-packages/errbot/plugin_manager.py", line 360, in activate_non_started_plugins errors += f'Notice: {plugin.name} is blacklisted, ' \ AttributeError: 'BotPluginManager' object has no attribute 'bot'



### Additional info

This issue is about fixing the `AttributeError`, but I also wonder why blacklisted plugins are emitted as errors at all. With the error fixed, my Slack bot prints out the blacklisted plugins _in Slack_, so I end up with this output every time it starts:

![Screenshot from 2019-07-23 12-24-34](https://user-images.githubusercontent.com/2316447/61704816-de45ab80-ad44-11e9-81a6-70c2ab6ad183.png)

W...why? I can understand it as log output, but I don't want that information in Slack. Is there an option to toggle that behavior?

Also, I often feel making issues sound like ungrateful complaining so I just want to take a brief second to thank the authors and contributors for making this project available :heart: 
sijis commented 4 years ago

This should be fixed in the latest release. Please reopen if issue persist.

duhow commented 3 years ago

@sijis PR #1369 was merged but as of version 6.1.6 this is not applied. Can you help check this and pick that commit for the next release? https://github.com/errbotio/errbot/blob/99ba74850200bd87d5f1a3b3b442d1fd8d30eb64/errbot/plugin_manager.py#L366

sijis commented 3 years ago

@sijis PR #1369 was merged but as of version 6.1.6 this is not applied. Can you help check this and pick that commit for the next release?

https://github.com/errbotio/errbot/blob/99ba74850200bd87d5f1a3b3b442d1fd8d30eb64/errbot/plugin_manager.py#L366

Yikes! Yeah, looks like it was missed. I'll include it in a new release.