beemdevelopment/Aegis · error · VaultRepositoryException

Invalid backups versioning strategy

Error message

Invalid backups versioning strategy

What it means

Exhaustiveness guard in VaultBackupManager.createBackup: thrown as VaultRepositoryException when the BackupsVersioningStrategy value is neither SINGLE_BACKUP nor MULTIPLE_BACKUP. This can only happen if a new strategy enum constant is added without extending createBackup, or a corrupt/unknown strategy is deserialized from preferences; it prevents backups proceeding with undefined versioning behavior.

Solutions

  1. Replace the bare else-branch throw with an exhaustive switch over BackupsVersioningStrategy so new enum values cause a compile error rather than a runtime failure
  2. Validate strategy != null and is a known value in scheduleBackup before dispatching to createBackup
  3. Include the actual strategy value in the exception message to make misconfiguration diagnosable
  4. Add a unit test covering every enum constant to guarantee each dispatch path is handled
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at app/src/main/java/com/beemdevelopment/aegis/vault/VaultBackupManager.java:80 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of beemdevelopment/Aegis@d6f4e5925a (2026-09-08). Data as JSON: /api/errors/57c4ce0c4678530d. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/com/beemdevelopment/aegis/vault/VaultBackupManager.java:80

                _prefs.setBuiltInBackupResult(new Preferences.BackupResult(null));
            } catch (VaultRepositoryException | VaultBackupPermissionException e) {
                e.printStackTrace();
                _prefs.setBuiltInBackupResult(new Preferences.BackupResult(e));
            }
        });
    }

    private void createBackup(File tempFile, BackupsVersioningStrategy strategy, Uri uri, int versionsToKeep)
            throws VaultRepositoryException, VaultBackupPermissionException {
        if (uri == null) {
            throw new VaultRepositoryException("getBackupsLocation returned null");
        }
        if (strategy == BackupsVersioningStrategy.SINGLE_BACKUP) {
            createBackup(tempFile, uri);
        } else if (strategy == BackupsVersioningStrategy.MULTIPLE_BACKUPS) {
            createBackup(tempFile, uri, versionsToKeep);
        } else {
            throw new VaultRepositoryException("Invalid backups versioning strategy");
        }
    }

    private void createBackup(File tempFile, Uri fileUri)
            throws VaultRepositoryException, VaultBackupPermissionException {
        Log.i(TAG, String.format("Creating backup at %s", fileUri));
        try {
            if (!hasPermissionsAt(fileUri)) {
                throw new VaultBackupPermissionException("No persisted URI permissions");
            }
            ContentResolver resolver = _context.getContentResolver();
            try (FileInputStream inStream = new FileInputStream(tempFile);
                 OutputStream outStream = resolver.openOutputStream(fileUri, "wt")
            ) {
                if (outStream == null) {
                    throw new IOException("openOutputStream returned null");
                }
                IOUtils.copy(inStream, outStream);

View on GitHub (pinned to d6f4e5925a)