Skip to content

Report failed repositories to the caller and in the exit status - #57

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/report-failed-backups
Nov 4, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/report-failed-backups

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • BackupService.backupUserRepositories still attempts every repository, but now throws an IOException naming the failed ones (Failed to back up 1 of 8 repositories for octocat: Hello-World). All three callers already catch IOException, so POST /api/backups answers 500 instead of 200 with a success message, and the daemon logs the failure as an error.
  • A non-interactive command-line run in which anything failed now exits with status 1 and ends with Backup completed with errors. instead of exiting 0 after Backup completed!. BackupCommandLineRunner implements ExitCodeGenerator, and GhBackupApplication.main exits through SpringApplication.exit only when that runner is present, so web and daemon modes keep running.
  • COMMANDS.md gains an Exit Status section and the new 500 case, USER_GUIDE.md gains a scenario for detecting a failure from a script, and CHANGELOG.md is updated.

Behaviour changes worth checking

  • A partly failed web backup no longer sends a backup-completed usage event, because the controller sends it only on success. This matches how a fatal failure already behaved. Command-line and daemon runs still report the event when they fail, as the existing tests specify.
  • An interactive session always exits 0, since each failure is reported at the prompt.
  • A failed run now exits non-zero, so an existing script that treated gh-backup as always succeeding could start stopping at this step.

Test plan

  • mvn -o test: 196 tests run, 0 failures, 0 errors, 1 skipped
  • Regression tests confirmed empirically: with the BackupService change stashed, testBackupUserRepositories_FailedRepositoryIsSummarizedAndOthersContinue and testBackupUserRepositories_AllRepositoriesFailing_AreAllNamed fail; with the assignment of the exit code removed, testGetExitCode_FailedUser, testGetExitCode_LaterSuccessDoesNotClearAnEarlierFailure and testExitStatus_FailedBackupReachesSpringApplicationExit fail. All pass with the fix restored.
  • Not verified: the System.exit call in GhBackupApplication.main was not executed, because launching the JAR was refused by this session's sandbox. Its condition (isCommandLineRun, in default, web and daemon modes) and the status returned by SpringApplication.exit are tested in a Spring context, but the real process status has not been observed. A manual check is recommended: run the JAR with a nonexistent user and read $?.

Closes #55
Closes #56

Skipped issues

#8 (missing LICENSE) remains deferred: it requires the maintainer to choose the license text, copyright holder and year.

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

🤖 Generated with Claude Code

A failed clone or fetch only printed a warning, so POST /api/backups
answered 200 with a success message and the command line exited 0.
BackupService now throws after attempting every repository, and a
non-interactive run that fails exits with status 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric, run against head 75680cc. This is a self-review by the authoring session, not an independent review. The Copilot reviewer request failed (Could not resolve user with login 'copilot').

  • Scope: PASS — all 9 files serve POST /api/backups reports success when repositories failed to back up #55 or Command-line run exits 0 when a backup fails #56; 202 insertions, 4 deletions, of which 142 insertions are tests.
  • Tests-new: PARTIAL — getExitCode and isCommandLineRun are tested, but the System.exit line in main is not executed by any test.
  • Tests-fix: PASS — with the BackupService change stashed, 2 tests failed; with the exit-code assignment removed, 3 tests failed; all passed once restored. The full stash form could not apply to the runner, because its tests reference symbols added by the fix.
  • Sibling structure: PASS — the new test methods follow test<MethodName>_<Scenario>, and the Exit Status section follows the COMMANDS.md heading and table style.
  • Sibling renames: PASS — nothing was renamed.
  • Docs: PASS — COMMANDS.md, USER_GUIDE.md and CHANGELOG.md were updated. README.md and CONFIG.md make no claim about failure reporting or exit status, and no property was added.
  • Issue resolution: PASS — POST /api/backups reports success when repositories failed to back up #55 is resolved in BackupService and Command-line run exits 0 when a backup fails #56 in the runner and main.
  • CI: PASS — build and docker-build succeeded on run 41773227690, whose headSha was confirmed to equal the PR head.
  • Config-doc parity: PASS — no property was added or changed.
  • Command-doc parity: PASS — no flag or endpoint was added; the new 500 case and the exit statuses are documented.
  • Package placement: PASS — no class was added.
  • No credential leakage: PASS — the new message contains the user or organization name, repository names and counts only.

Regression gate: the fix tests listed above satisfy it. Do-not-auto-merge paths: none matched (no pom.xml, properties or workflow file, and no file with over 50 lines deleted).

Findings:

  • src/main/java/com/github/backup/GhBackupApplication.java:15 — the process exit itself is unverified. Launching the JAR was refused by the sandbox, so the real exit status was not observed. The condition and the value passed to System.exit are both tested in a Spring context, and System.exit(SpringApplication.exit(context)) is the idiom documented by Spring Boot, so the remaining risk is judged low. A manual run with a nonexistent user remains worthwhile.
  • src/main/java/com/github/backup/GhBackupApplication.java:19 — a command-line run that also sets spring.main.web-application-type=servlet without the web profile previously left the server running after the runner finished, and now exits. That combination is undocumented (CONFIG.md says the property is managed by the web profile), so no change was made.
  • src/main/java/com/github/backup/BackupService.java:83 — one repository failure in a large organization now fails the whole POST /api/backups response, even though the rest were backed up. This is deliberate: the message reports how many failed, and a partial backup is not presented as a success.

This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 9da6deb into main Nov 4, 2026
2 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/report-failed-backups branch November 4, 2026 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command-line run exits 0 when a backup fails POST /api/backups reports success when repositories failed to back up

1 participant