Print exception tracebacks in voice threads
Errors occurring within `AudioSource.read()` and `after()` functions will now display their tracebacks as if they were unhandled exceptions.
This commit is contained in:
parent
7df5effbb7
commit
839afce178
@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
import traceback
|
||||||
import subprocess
|
import subprocess
|
||||||
import audioop
|
import audioop
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -32,6 +33,7 @@ import logging
|
|||||||
import shlex
|
import shlex
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .errors import ClientException
|
from .errors import ClientException
|
||||||
@ -602,11 +604,20 @@ class AudioPlayer(threading.Thread):
|
|||||||
self._call_after()
|
self._call_after()
|
||||||
|
|
||||||
def _call_after(self):
|
def _call_after(self):
|
||||||
|
error = self._current_error
|
||||||
|
|
||||||
if self.after is not None:
|
if self.after is not None:
|
||||||
try:
|
try:
|
||||||
self.after(self._current_error)
|
self.after(error)
|
||||||
except Exception:
|
except Exception as exc:
|
||||||
log.exception('Calling the after function failed.')
|
log.exception('Calling the after function failed.')
|
||||||
|
exc.__context__ = error
|
||||||
|
traceback.print_exception(type(exc), exc, exc.__traceback__)
|
||||||
|
elif error:
|
||||||
|
msg = 'Exception in voice thread {}'.format(self.name)
|
||||||
|
log.exception(msg, exc_info=error)
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
traceback.print_exception(type(error), error, error.__traceback__)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._end.set()
|
self._end.set()
|
||||||
|
@ -338,7 +338,8 @@ class VoiceClient:
|
|||||||
or an error occurred.
|
or an error occurred.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
-----------
|
-----------
|
||||||
@ -346,9 +347,8 @@ class VoiceClient:
|
|||||||
The audio source we're reading from.
|
The audio source we're reading from.
|
||||||
after: Callable[[:class:`Exception`], Any]
|
after: Callable[[:class:`Exception`], Any]
|
||||||
The finalizer that is called after the stream is exhausted.
|
The finalizer that is called after the stream is exhausted.
|
||||||
All exceptions it throws are silently discarded. This function
|
This function must have a single parameter, ``error``, that
|
||||||
must have a single parameter, ``error``, that denotes an
|
denotes an optional exception that was raised during playing.
|
||||||
optional exception that was raised during playing.
|
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
-------
|
-------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user