Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opsdroid logger returning errors #1429

Closed
gideongrinberg opened this issue Apr 14, 2020 · 9 comments · Fixed by #1432
Closed

Opsdroid logger returning errors #1429

gideongrinberg opened this issue Apr 14, 2020 · 9 comments · Fixed by #1432

Comments

@gideongrinberg
Copy link
Contributor

gideongrinberg commented Apr 14, 2020

Description

Hi, I have been using opsdroid for a few days now, and while it is a good framework, I have been having a lot of trouble. Most recently I have been getting a error formatter refrenced before use. I have linted my configuration.yaml and none of my python files have errors. The error message below only shows errors in opsdroid library files. Even so, I am probably doing something wrong. Any help is greatly appreciated!

Steps to Reproduce

I just linted and built my config. Neither of those actions returned errors.

Expected Functionality

My bot should have run on Telegram and in bash.

Experienced Functionality

Traceback (most recent call last):
  File "/home/gideongrinberg/.local/bin/opsdroid", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/gideongrinberg/.local/lib/python3.6/site-packages/opsdroid/cli/start.py", line 38, in start
    configure_logging(config)
  File "/home/gideongrinberg/.local/lib/python3.6/site-packages/opsdroid/logging.py", line 93, in configure_logging
    console_handler.setFormatter(formatter)
UnboundLocalError: local variable 'formatter' referenced before assignment

Versions

  • Opsdroid version: 0.17.1
  • Python version: Python 3.6.9
  • OS/Docker version: Ubuntu 18.04 on Window Subsystem Linux (Windows 10)

Configuration File

My config.yaml is to large to include, but this is the only line I've change from the example (other than adding tokens)

  recycle-nlp:
    path: '~/opdroid_recycle/skill-recycle-nlp'

Again, that file returns no errors when I run opsdroid config -f [PATH] lint or opsdroid config -f [PATH] build.

Additionally, the python file:

from opsdroid.skill import Skill
from opsdroid.matchers import match_luisai_intent

class recycle-nlp(Skill):
@match_luisai_intent('recycle')
    async def recycle-nlp(self, message):
        if message.luisai["topScoringIntent"]["intent"]=="recycle":
            await message.respond(str(message.luisai))

My directory structure (/home for WSL, not windows):

| /home
            |____ opsdroid_recycle
                           |
                           |_____ config.yaml
                           |_____skill-recycle-nlp
                                               |
                                               |____ __init__.py
                                                |______ README.md
                                                |______ LICENSE
           |
           |___.local/lib/python3.6/site-packages

Additional Details

Interestingly, my bot worked fine with the example config

Any help is much appreciated!

@nzlosh
Copy link

nzlosh commented Apr 15, 2020

I've hit the same error, when enabling logging as defined in the default configuration sourced from https://raw.githubusercontent.com/opsdroid/opsdroid/master/opsdroid/configuration/example_configuration.yaml.

The block that triggers the error is:

logging:
  level: info
  path: opsdroid.log
  console: true
  extended: false
  filter:
    whitelist:
      - opsdroid.core
    blacklist:
      - opsdroid.loader

The error message is as follows

opsdroid start -f /opt/opsdroid/configuration.yaml 
Traceback (most recent call last):
  File "/opt/opsdroid/bin/opsdroid", line 8, in <module>
    sys.exit(cli())
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/opsdroid/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/opt/opsdroid/lib/python3.7/site-packages/opsdroid/cli/start.py", line 38, in start
    configure_logging(config)
  File "/opt/opsdroid/lib/python3.7/site-packages/opsdroid/logging.py", line 93, in configure_logging
    console_handler.setFormatter(formatter)
UnboundLocalError: local variable 'formatter' referenced before assignment

Version

pip freeze | grep opsdroid
opsdroid==0.17.1

@gideongrinberg
Copy link
Contributor Author

gideongrinberg commented Apr 15, 2020

@nzlosh where you able to fix this? Did you try opsdroid config -f [PATH] lint?

@gideongrinberg
Copy link
Contributor Author

@nzlosh this issue appears to be logging related. The formatter is defined in logging.py. @FabioRosado appears to have worked on that file most recently, so maybe he can shed some light on how to fix this.

@FabioRosado
Copy link
Member

Hello @Gideon357 and @nzlosh Thank you for raising this issue and I'd like to apologise for the troubles you are having with opsdroid.

Just out of curiosity are you setting your logging with the extended set to false and do you have any whitelist or blacklist filter set to it?

I might have botched up something while creating the extended filter. I'm going to work on this issue tomorrow and hopefully fix it.

@gideongrinberg gideongrinberg changed the title Opsdroid library returning errors Opsdroid logger returning errors Apr 15, 2020
@gideongrinberg
Copy link
Contributor Author

@FabioRosado thanks for responding. I was using the default configuration that I generated using opsdroid config gen > config.yaml. If you need help fixing it, let me know. I do know @nzlosh had his logging setup like this:

logging:
  level: info
  path: opsdroid.log
  console: true
  extended: false
  filter:
    whitelist:
      - opsdroid.core
    blacklist:
      - opsdroid.loader

@FabioRosado
Copy link
Member

Hello @Gideon357 I've just submitted a PR to hopefully fix the issues you are having with opsdroid. Looking at the code I'm not sure why you were getting that exception, but decided to move the normal formatter outside the try/except block so hopefully this fix will work for you.

We are having a bit of trouble with Travis reporting the status to github, so I'll try to get this PR merged as soon as possible. Feel free to test the fix on your end until we get this merged and patch opsdroid 😄 👍

@FabioRosado
Copy link
Member

Gideon, cadair have merged the PR so hopefully this fixes the issue. We will need to do a release/patch if you are using opsdroid installed from pip you might need to wait a bit. Unless you want to clone the repo and test it from the dev version 👍

@gideongrinberg
Copy link
Contributor Author

Thank you @FabioRosado and @Cadair. When will this release come out. It seems like an important patch.

@FabioRosado
Copy link
Member

Hello @Gideon357 thank you for the message, Jacob just released the latest opsdroid version yesterday night. If you update your opsdroid version the fix should be there. Please let us know if you get the same or any other issues 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants