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

- `POST /api/backups` now answers a backup that fails with an unchecked exception (such as a `GHException` from github-api while listing repositories) with `500 Internal Server Error` and `{ "success": false, "message": "Error: ..." }`, as `COMMANDS.md` documents, instead of Spring Boot's default error body, which has no `message`, so the web UI showed only `Failed to create backup.`. No `backup-completed` event is reported for it. Previously only an `IOException` was handled this way; the command line and daemon already handled both
- The interactive `backup` command now backs up each name it is given, so `backup octocat github` backs up `octocat` and then `github`, as the command line does, instead of looking up the single name `octocat github` on GitHub and failing. A name that fails is reported and the others are still backed up; the command still counts as one backup run for usage reporting, and its usage hint reads `Usage: backup <user/org> [user/org2] ...`
- Interactive mode's command list, printed on start and by `help`, now shows `backup <user/org> [user/org2] ...` instead of `backup <user/org>`, so it no longer suggests that `backup` takes a single name
- 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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/backup/web/BackupController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;

Expand Down Expand Up @@ -38,7 +37,8 @@ public ResponseEntity<BackupResponse> createBackup(@Valid @RequestBody BackupReq
backupService.backupUserRepositories(request.getUserOrOrg());
usageReporting.backupCompleted();
return ResponseEntity.ok(new BackupResponse(true, "Backup completed successfully for " + request.getUserOrOrg()));
} catch (IOException e) {
} catch (Exception e) {
// Unchecked failures too (a GHException from github-api, say), as the CLI and daemon handle them
return ResponseEntity.status(500)
.body(new BackupResponse(false, "Error: " + e.getMessage()));
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/github/backup/web/BackupControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ void createBackup_Failure() throws Exception {
verify(usageReporting, never()).backupCompleted();
}

@Test
void createBackup_UncheckedFailure() throws Exception {
doThrow(new IllegalStateException("Unchecked test error")).when(backupService).backupUserRepositories(anyString());

mockMvc.perform(post("/api/backups")
.contentType(MediaType.APPLICATION_JSON)
.content("{\"userOrOrg\":\"testuser\"}"))
.andExpect(status().isInternalServerError())
.andExpect(jsonPath("$.success").value(false))
.andExpect(jsonPath("$.message").value("Error: Unchecked test error"));

verify(backupService, times(1)).backupUserRepositories("testuser");
verify(usageReporting, never()).backupCompleted();
}

@Test
void createBackup_Success_ReportsBackupCompleted() throws Exception {
mockMvc.perform(post("/api/backups")
Expand Down
Loading