Cog-Creators / Cog-Creators/Red-DiscordBot

Backup restore logging drops cog names and raises TypeError for failed libraries

Open Beginner friendly
#6,792 1 comment 0 reactions 0 assignees View on GitHub
Category: Core - Command-line Interfaces Status: Needs Triage Type: Bug
Dominant language
Python
Stars
5.7k
Forks
2.5k
Avg merge
6d 16h
Merged PRs (30d)
1

Description

### What Red version are you using?

3.5.25.dev1 (V3/develop @ 61484f28f7fcfff81309cb2b0b0d5287c921f1ad)

### What were you trying to do?

Restore third-party cogs from a Red backup with `redbot-setup restore`. I audited the failure reporting in `redbot.core._downloader._restore_from_backup()` because these messages are the only diagnostic output when a cog cannot be restored.

### What did you expect to happen?

Every restore failure should produce a normal log record containing the cog name, repository name, and failed shared-library names. Logging a recovery failure must not itself raise a formatting exception.

### What actually happened?

Three log calls in the restore path have missing format arguments.

- Lines 989 and 994 log `The commit that %r cog...` without passing `cog.name`, so the literal placeholder is printed instead of the affected cog.
- The `failed_libs` branch at lines 1066-1069 has three placeholders but passes only two arguments. Python logging raises `TypeError: not enough arguments for format string`, and the intended failure message is lost.

Observed output:

WARNING:The commit that %r cog was installed from is unknown ...
ERROR:The commit that %r cog was installed from is unknown ...
--- Logging error ---
TypeError: not enough arguments for format string
Message: 'Failed to reinstall shared libraries for %r cog from %r repo: %s'
Arguments: ('repo-name', 'lib-name')

### How can we reproduce this error?

1. Check out `V3/develop` at `61484f28f7fcfff81309cb2b0b0d5287c921f1ad` and install the test dependencies on Python 3.11.
2. Attach a `logging.StreamHandler` to `red.core.downloader`.
3. Exercise the two no-commit branches in `_restore_from_backup()`; both records retain a literal `%r`.
4. Return a `CogInstallResult` with a non-empty `failed_libs` tuple from `install_cogs()`.
5. Observe the logging traceback above instead of the intended cog/repository/library diagnostic.

The same failure can be isolated with the production format string:

log.error(
'Failed to reinstall shared libraries for %r cog from %r repo: %s',
'repo-name',
'lib-name',
)

### Anything else?

Environment: Debian Bookworm arm64 container, Python 3.11.15. The unmodified baseline passes `313 passed, 7 skipped`; `pylint --errors-only redbot` independently reports E1206 at line 1066. I searched open and closed issues for the exact messages, backup restore logging errors, failed shared libraries, and missing commit metadata; no duplicate was found.

Likely minimal fix: pass `cog.name` to both missing-commit messages, and pass `cog.name`, `cog.repo.name`, then the joined library names to the failed-libraries message. I will add regression coverage for all three formatted records separately.

Contributor guide

Open the contributing guide

Research direction

Start in redbot.core._downloader._restore_from_backup() and inspect the three restore logging calls described in the issue. Reproduce the no-commit and failed-libraries branches, then add regression coverage for each formatted record. Done means every message includes the cog, repository, and failed-library details without a logging TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.