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

Include command-line arguments in debuginfo #6164

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions redbot/core/_debuginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import getpass
import os
import platform
import re
Jackenmen marked this conversation as resolved.
Show resolved Hide resolved
import sys
from typing import Optional

Expand Down Expand Up @@ -143,6 +144,24 @@ async def _get_red_vars_section(self) -> DebugInfoSection:
parts = [f"Instance name: {instance_name}"]

if self.bot is not None:
# sys.original_argv is available since 3.10 and shows the actual command line arguments
# rather than a Python-transformed version (i.e. with '-c' or path to `__main__.py`
# as first element). We could just not show the first argument for consistency
# but it can be useful.
cli_args = getattr(sys, "orig_argv", sys.argv).copy()
# best effort attempt to expunge a token argument
for idx, arg in enumerate(cli_args):
if not arg.startswith("--to"):
continue
arg_name, sep, arg_value = arg.partition("=")
if arg_name not in ("--to", "--tok", "--toke", "--token"):
continue
if sep:
cli_args[idx] = f"{arg_name}{sep}[EXPUNGED]"
elif len(cli_args) > idx + 1:
cli_args[idx + 1] = f"[EXPUNGED]"
parts.append(f"Command line arguments: {cli_args!r}")

# This formatting is a bit ugly but this is a debug information command
# and calling repr() on prefix strings ensures that the list isn't ambiguous.
prefixes = ", ".join(map(repr, await self.bot._config.prefix()))
Expand Down