Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
- redbot/core/_cli.py
- redbot/core/_debuginfo.py
- redbot/setup.py
- tests/core/test_dry_run.py
"Category: Core - Help":
- redbot/core/commands/help.py
"Category: Core - i18n":
Expand Down
10 changes: 9 additions & 1 deletion redbot/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,15 @@ async def _delete_helper(m):

async def close(self):
"""Logs out of Discord and closes all connections."""
await super().close()
try:
await super().close()
except AttributeError as e:
if "'Red' object has no attribute '_AutoShardedClient__queue'" in str(e):
# The client never finished starting up, so the queue was never created.
pass
else:
raise e

await _drivers.get_driver_class().teardown()
try:
if self.rpc_enabled:
Expand Down
36 changes: 36 additions & 0 deletions tests/core/test_dry_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Integration test ensuring `redbot --dry-run` exits cleanly."""

from __future__ import annotations

import subprocess
import sys


def test_dry_run_exits_cleanly():
"""Running `redbot --dry-run` should exit with code 0 and without AttributeError."""
result = subprocess.run(
[
sys.executable,
"-m",
"redbot",
"--no-instance",
"--dry-run",
"--no-prompt",
"--token",
"dummy_token_for_testing",
"--prefix",
"!",
],
capture_output=True,
text=True,
timeout=30,
)

assert result.returncode == 0, (
"Expected redbot dry-run to exit with code 0, "
f"got {result.returncode}.\nSTDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}"
)
assert "AttributeError" not in result.stderr, (
"redbot dry-run emitted AttributeError on stderr, indicating shutdown guard failed.\n"
f"STDERR:\n{result.stderr}"
)
Loading