# Buggy code
async def _run(
    self,
    *args: Any,
    valid_exit_codes: Tuple[int, ...] = (0,),
    debug_only: bool = False,
    **kwargs: Any,
) -> CompletedProcess:
    """
    Parameters
    ----------
    valid_exit_codes : tuple
        Specifies valid exit codes, used to determine
        if stderr should be sent as debug or error level in logging.
        When not provided, defaults to :code:`(0,)`
    debug_only : bool
        Specifies if stderr can be sent only as debug level in logging.
        When not provided, defaults to `False`
    """
    env = os.environ.copy()
    env["GIT_TERMINAL_PROMPT"] = "0"
    env.pop("GIT_ASKPASS", None)
    # attempt to force all output to plain ascii english
    # some methods that parse output may expect it
    # according to gettext manual both variables have to be set:
    # https://www.gnu.org/software/gettext/manual/gettext.html#Locale-Environment-Variables
    env["LC_ALL"] = "C"
    env["LANGUAGE"] = "C"
    kwargs["env"] = env
    async with self._repo_lock:
        p: CompletedProcess = await asyncio.get_running_loop().run_in_executor(
            self._executor,
            functools.partial(sp_run, *args, stdout=PIPE, stderr=PIPE, **kwargs),
        )
        stderr = p.stderr.decode().strip()
        if stderr:
            if debug_only or p.returncode in valid_exit_codes:
                log.debug(stderr)
            else:
                log.error(stderr)
        return p


# Traceback (UnicodeDecodeError)
[ERROR] red: Exception in command 'cog update'
Traceback (most recent call last):
File "c:\__\coding\redenv\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "c:\__\coding\redenv\lib\site-packages\redbot\cogs\downloader\downloader.py", line 885, in _cog_update
await self._cog_update_logic(ctx, cogs=cogs)
File "c:\__\coding\redenv\lib\site-packages\redbot\cogs\downloader\downloader.py", line 979, in _cog_update_logic
updated_cognames, message = await self._update_cogs_and_libs(
File "c:\__\coding\redenv\lib\site-packages\redbot\cogs\downloader\downloader.py", line 1237, in _update_cogs_and_libs
failed_reqs = await self._install_requirements(cogs_to_update)
File "c:\__\coding\redenv\lib\site-packages\redbot\cogs\downloader\downloader.py", line 434, in _install_requirements
if not await repo.install_raw_requirements([req], self.LIB_PATH):
File "c:\__\coding\redenv\lib\site-packages\redbot\cogs\downloader\repo_manager.py", line 931, in install_raw_requirements
p = await self._run(
File "c:\__\coding\redenv\lib\site-packages\redbot\cogs\downloader\repo_manager.py", line 533, in _run
stderr = p.stderr.decode().strip()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc5 in position 936: invalid continuation byte

# Fixed code
async def _run(
    self,
    *args: Any,
    valid_exit_codes: Tuple[int, ...] = (0,),
    debug_only: bool = False,
    **kwargs: Any,
) -> CompletedProcess:
    """
    Parameters
    ----------
    valid_exit_codes : tuple
        Specifies valid exit codes, used to determine
        if stderr should be sent as debug or error level in logging.
        When not provided, defaults to :code:`(0,)`
    debug_only : bool
        Specifies if stderr can be sent only as debug level in logging.
        When not provided, defaults to `False`
    """
    env = os.environ.copy()
    env["GIT_TERMINAL_PROMPT"] = "0"
    env.pop("GIT_ASKPASS", None)
    # attempt to force all output to plain ascii english
    # some methods that parse output may expect it
    # according to gettext manual both variables have to be set:
    # https://www.gnu.org/software/gettext/manual/gettext.html#Locale-Environment-Variables
    env["LC_ALL"] = "C"
    env["LANGUAGE"] = "C"
    kwargs["env"] = env
    async with self._repo_lock:
        p: CompletedProcess = await asyncio.get_running_loop().run_in_executor(
            self._executor,
            functools.partial(sp_run, *args, stdout=PIPE, stderr=PIPE, **kwargs),
        )
        # logging can't use surrogateescape
        stderr = p.stderr.decode(encoding="utf-8", errors="replace").strip()
        if stderr:
            if debug_only or p.returncode in valid_exit_codes:
                log.debug(stderr)
            else:
                log.error(stderr)
        return p