Browse Source

Change View, Modal, and AudioPlayer to use logger instead of stderr

pull/8173/head
mniip 3 years ago
committed by GitHub
parent
commit
1be36c9c3e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      discord/player.py
  2. 7
      discord/ui/modal.py
  3. 6
      discord/ui/view.py
  4. 5
      discord/voice_client.py
  5. 1
      docs/migrating.rst

9
discord/player.py

@ -24,7 +24,6 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations from __future__ import annotations
import threading import threading
import traceback
import subprocess import subprocess
import audioop import audioop
import asyncio import asyncio
@ -709,14 +708,10 @@ class AudioPlayer(threading.Thread):
try: try:
self.after(error) self.after(error)
except Exception as exc: except Exception as exc:
_log.exception('Calling the after function failed.')
exc.__context__ = error exc.__context__ = error
traceback.print_exception(type(exc), exc, exc.__traceback__) _log.exception('Calling the after function failed.', exc_info=exc)
elif error: elif error:
msg = f'Exception in voice thread {self.name}' _log.exception('Exception in voice thread %s', self.name, exc_info=error)
_log.exception(msg, exc_info=error)
print(msg, file=sys.stderr)
traceback.print_exception(type(error), error, error.__traceback__)
def stop(self) -> None: def stop(self) -> None:
self._end.set() self._end.set()

7
discord/ui/modal.py

@ -27,8 +27,6 @@ from __future__ import annotations
import asyncio import asyncio
import logging import logging
import os import os
import sys
import traceback
from copy import deepcopy from copy import deepcopy
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, ClassVar, List from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, ClassVar, List
@ -154,7 +152,7 @@ class Modal(View):
A callback that is called when :meth:`on_submit` A callback that is called when :meth:`on_submit`
fails with an error. fails with an error.
The default implementation prints the traceback to stderr. The default implementation logs to the library logger.
Parameters Parameters
----------- -----------
@ -163,8 +161,7 @@ class Modal(View):
error: :class:`Exception` error: :class:`Exception`
The exception that was raised. The exception that was raised.
""" """
print(f'Ignoring exception in modal {self}:', file=sys.stderr) _log.error('Ignoring exception in modal %r:', self, exc_info=error)
traceback.print_exception(error.__class__, error, error.__traceback__, file=sys.stderr)
def _refresh(self, components: Sequence[ModalSubmitComponentInteractionDataPayload]) -> None: def _refresh(self, components: Sequence[ModalSubmitComponentInteractionDataPayload]) -> None:
for component in components: for component in components:

6
discord/ui/view.py

@ -27,7 +27,6 @@ from typing import Any, Callable, ClassVar, Coroutine, Dict, Iterator, List, Opt
from functools import partial from functools import partial
from itertools import groupby from itertools import groupby
import traceback
import asyncio import asyncio
import logging import logging
import sys import sys
@ -388,7 +387,7 @@ class View:
A callback that is called when an item's callback or :meth:`interaction_check` A callback that is called when an item's callback or :meth:`interaction_check`
fails with an error. fails with an error.
The default implementation prints the traceback to stderr. The default implementation logs to the library logger.
Parameters Parameters
----------- -----------
@ -399,8 +398,7 @@ class View:
item: :class:`Item` item: :class:`Item`
The item that failed the dispatch. The item that failed the dispatch.
""" """
print(f'Ignoring exception in view {self} for item {item}:', file=sys.stderr) _log.error('Ignoring exception in view %r for item %r', self, item, exc_info=error)
traceback.print_exception(error.__class__, error, error.__traceback__, file=sys.stderr)
async def _scheduled_task(self, item: Item, interaction: Interaction): async def _scheduled_task(self, item: Item, interaction: Interaction):
try: try:

5
discord/voice_client.py

@ -572,7 +572,10 @@ class VoiceClient(VoiceProtocol):
If an error happens while the audio player is running, the exception is If an error happens while the audio player is running, the exception is
caught and the audio player is then stopped. If no after callback is caught and the audio player is then stopped. If no after callback is
passed, any caught exception will be displayed as if it were raised. passed, any caught exception will be logged using the library logger.
.. versionchanged:: 2.0
Instead of writing to ``sys.stderr``, the library's logger is used.
Parameters Parameters
----------- -----------

1
docs/migrating.rst

@ -941,6 +941,7 @@ The library now provides a default logging configuration if using :meth:`Client.
- :meth:`Client.on_error` - :meth:`Client.on_error`
- :meth:`discord.ext.tasks.Loop.error` - :meth:`discord.ext.tasks.Loop.error`
- :meth:`discord.ext.commands.Bot.on_command_error` - :meth:`discord.ext.commands.Bot.on_command_error`
- :meth:`VoiceClient.play`
For more information, check :doc:`logging`. For more information, check :doc:`logging`.

Loading…
Cancel
Save