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

logging: don't crash if backend is uninitialized #2020

Merged
merged 1 commit into from
Feb 22, 2021

Conversation

half-duplex
Copy link
Member

Description

When core.logging_channel is used, errors early in startup cause an exception that halts the bot. (bdc10e0, current master)

Repro

sopel.cfg

[core]
host = fake.local
logging_channel = #services
owner = mal
enable = version
foo = bar

Start the bot: sopel start -c sopel.cfg

Current Result

  File "sopel/logger.py", line 32, in emit
    if not self._bot.backend.is_connected():
AttributeError: 'NoneType' object has no attribute 'is_connected'
full logs
(env) [mal@nova sopel-test]$ sopel start -c sopel.cfg
Sopel 7.1.0.dev0 (running on Python 3.8.5)
https://sopel.chat/

Loaded config file: /home/mal/sources/sopel-test/sopel.cfg
[2021-01-23 03:18:54,137] sopel.bot            INFO     - Loading plugins...
[2021-01-23 03:18:54,142] sopel.bot            INFO     - Plugin loaded: version
[2021-01-23 03:18:54,149] sopel.bot            INFO     - Plugin loaded: coretasks
[2021-01-23 03:18:54,150] sopel.bot            INFO     - Registered 1 plugins, 0 failed, 39 disabled
[2021-01-23 03:18:54,150] sopel.bot            WARNING  - Config option `core.foo` is not defined by its section and may not be recognized by Sopel.
Unexpected error in bot setup
Traceback (most recent call last):
  File "/home/mal/sources/sopel-test/env/bin/sopel", line 8, in <module>
    sys.exit(main())
  File "/home/mal/sources/sopel-test/env/lib/python3.8/site-packages/sopel/cli/run.py", line 714, in main
    return command(opts)
  File "/home/mal/sources/sopel-test/env/lib/python3.8/site-packages/sopel/cli/run.py", line 439, in command_start
    ret = run(settings, pid_file_path)
  File "/home/mal/sources/sopel-test/env/lib/python3.8/site-packages/sopel/cli/run.py", line 75, in run
    p.setup()
  File "/home/mal/sources/sopel-test/env/lib/python3.8/site-packages/sopel/bot.py", line 280, in setup
    self.post_setup()
  File "/home/mal/sources/sopel-test/env/lib/python3.8/site-packages/sopel/bot.py", line 369, in post_setup
    LOGGER.warning(
  File "/usr/lib/python3.8/logging/__init__.py", line 1446, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/lib/python3.8/logging/__init__.py", line 1577, in _log
    self.handle(record)
  File "/usr/lib/python3.8/logging/__init__.py", line 1587, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.8/logging/__init__.py", line 1649, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.8/logging/__init__.py", line 950, in handle
    self.emit(record)
  File "/home/mal/sources/sopel-test/env/lib/python3.8/site-packages/sopel/logger.py", line 32, in emit
    if not self._bot.backend.is_connected():
AttributeError: 'NoneType' object has no attribute 'is_connected'
(env) [mal@nova sopel-test]$ 

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make quality and make test)
  • I have tested the functionality of the things this change touches

@half-duplex half-duplex added the Bugfix Generally, PRs that reference (and fix) one or more issue(s) label Jan 23, 2021
@half-duplex half-duplex added this to the 7.1.0 milestone Jan 23, 2021
@dgw dgw merged commit 49f3950 into sopel-irc:master Feb 22, 2021
@half-duplex half-duplex deleted the logging-backend-none branch February 22, 2021 08:05
@half-duplex half-duplex restored the logging-backend-none branch May 14, 2023 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Generally, PRs that reference (and fix) one or more issue(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants