Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Fixed

- A scheduled daemon backup no longer stops partway when one user or organization fails with an unchecked exception (such as a `GHException` from github-api while listing repositories): the failure is logged as an error like any other, the remaining users and organizations are still backed up, and the run is still logged and reported as completed. Previously only an `IOException` was handled, so the rest of that run was skipped until the next interval
- A backup that reaches the GitHub rate limit no longer looks hung: the GitHub client has always waited silently for the limit to reset, for up to an hour, and now a notice on standard error says so first, with the expected reset time, and suggests `GITHUB_TOKEN` when running anonymously. The waiting itself is unchanged and is documented in `USER_GUIDE.md` and `COMMANDS.md`
- `GITHUB_TOKEN` is no longer dropped when the startup check fails for a reason unrelated to the token: only a `401` now prints `Invalid or expired GITHUB_TOKEN` and falls back to anonymous access, while any other failure, such as a network failure, a GitHub error or a `403` from `GET /user`, prints `Could not verify GITHUB_TOKEN` and keeps the token, so a brief outage at startup no longer leaves a daemon limited to 60 requests per hour until it is restarted
- A GitHub failure is no longer reported as `not found as GitHub organization or user` just because its message contains `404`, as a connection failure's does for a name such as `team404`, and a real 404 is now recognized by its exception type instead of depending on the digits appearing in GitHub's response
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/backup/ScheduledBackupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.stereotype.Service;

import jakarta.annotation.PostConstruct;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
Expand Down Expand Up @@ -82,7 +81,8 @@ public void runScheduledBackup() {
for (String userOrOrg : scheduledUsers) {
try {
backupService.backupUserRepositories(userOrOrg);
} catch (IOException e) {
} catch (Exception e) {
// Any failure, checked or not, is this user's alone; the others still run
log.error("Error backing up {}: {}", userOrOrg, e.getMessage());
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/github/backup/ScheduledBackupServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,28 @@ void testRunScheduledBackup_LogsErrorForFailedUser() throws IOException {
verify(backupService, times(1)).backupUserRepositories("github");
}

@Test
void testRunScheduledBackup_UncheckedExceptionDoesNotStopRemainingUsers() throws IOException {
scheduledBackupService = new ScheduledBackupService(backupService, usageReporting, "octocat,github", DEFAULT_INTERVAL);

doThrow(new IllegalStateException("Listing interrupted")).when(backupService).backupUserRepositories("octocat");

assertDoesNotThrow(() -> scheduledBackupService.runScheduledBackup());

// The failure is logged like any other, and the rest of the run still happens
List<ILoggingEvent> logsList = logAppender.list;
assertTrue(logsList.stream().anyMatch(event ->
event.getLevel() == Level.ERROR &&
event.getFormattedMessage().contains("Error backing up octocat") &&
event.getFormattedMessage().contains("Listing interrupted")),
"Should log error with user name and error message");
assertTrue(logsList.stream().anyMatch(event ->
event.getFormattedMessage().contains("Scheduled backup completed")),
"Should log when backup completes");
verify(backupService, times(1)).backupUserRepositories("github");
verify(usageReporting, times(1)).backupCompleted();
}

@Test
void testRunScheduledBackup_WithNoUsers_NoLogsGenerated() {
scheduledBackupService = new ScheduledBackupService(backupService, usageReporting, "", DEFAULT_INTERVAL);
Expand Down
Loading