{"record":{"id":"d398d94f74474cf3","repo":"Devolutions/UniGetUI","slug":"the-cloud-backup-key-was-not-found","errorCode":null,"errorMessage":"The cloud backup \\\"{key}\\\" was not found.","messagePattern":"The cloud backup \\\\\"(.+?)\\\\\" was not found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"src/UniGetUI.Interface.IpcApi/IpcBackupApi.cs","lineNumber":519,"sourceCode":"\n    private static async Task<string> GetCloudBackupContentsAsync(string key)\n    {\n        using var client = CreateAuthenticatedGitHubClient();\n        await GetAuthenticatedGitHubUserAsync(client);\n        var backupGist = await GetBackupGistAsync(client, createIfMissing: false);\n        if (backupGist is null)\n        {\n            throw new InvalidOperationException(\"No cloud backups are available for the current account.\");\n        }\n\n        var fullGist = await client.GetGistAsync(backupGist.Id);\n        var file = fullGist.Files.FirstOrDefault(candidate =>\n            candidate.Key.StartsWith(PackageBackupStartingKey, StringComparison.Ordinal)\n            && candidate.Key.EndsWith(key, StringComparison.Ordinal));\n\n        if (file.Value?.Content is null)\n        {\n            throw new InvalidOperationException($\"The cloud backup \\\"{key}\\\" was not found.\");\n        }\n\n        return file.Value.Content;\n    }\n\n    private static async Task<GitHubGist?> GetBackupGistAsync(\n        GitHubApiClient client,\n        bool createIfMissing\n    )\n    {\n        var candidates = await client.GetCurrentUserGistsAsync();\n        var backupGist = candidates.FirstOrDefault(candidate =>\n            candidate.Description?.EndsWith(GistDescriptionEndingKey, StringComparison.Ordinal)\n            == true\n        );\n\n        if (backupGist is not null || !createIfMissing)\n        {","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/Devolutions/UniGetUI/blob/9b1d7d0eab91620fc15c86b36676532095936ae3/src/UniGetUI.Interface.IpcApi/IpcBackupApi.cs#L501-L537","documentation":"GetCloudBackupContentsAsync locates the backup gist (found), fetches the full gist via GetGistAsync, then searches gist.Files for an entry whose key StartsWith the package-backup prefix and EndsWith the requested key. If no matching file is found, or the file's Content is null, it throws InvalidOperationException with the key in the message. This means the gist exists but does not contain a backup for the specified machine/device key.","triggerScenarios":"DownloadCloudBackupAsync or RestoreCloudBackupAsync is called with a key that does not match any file in the backup gist. The key is from a different machine, was mistyped, or the corresponding backup file was removed from the gist.","commonSituations":"The user tries to restore from a machine key that was never backed up to this gist. The key was typed incorrectly. The backup file for that machine was manually removed from the gist. The user switched machines and the device identifier (MachineName\\UserName) changed, producing a different key.","solutions":["Call ListCloudBackupsAsync to enumerate the valid keys present in the gist, then use one of those.","Verify the key matches the display value from the backup list (it is derived from MachineName\\UserName).","If the key changed due to a machine/user rename, create a new backup from the current machine first."],"exampleFix":"// before: guessing a backup key\nawait IpcBackupApi.DownloadCloudBackupAsync(new IpcCloudBackupRequest { Key = \"old-pc\" });\n// after: select from the available list\nvar entries = await IpcBackupApi.ListCloudBackupsAsync();\nvar entry = entries.FirstOrDefault(e => e.IsCurrentMachine) ?? entries.FirstOrDefault();\nif (entry is not null)\n    await IpcBackupApi.DownloadCloudBackupAsync(new IpcCloudBackupRequest { Key = entry.Key });","handlingStrategy":"validation","validationCode":"var entries = await IpcBackupApi.ListCloudBackupsAsync();\nvar validKeys = entries.Select(e => e.Key).ToHashSet(StringComparer.OrdinalIgnoreCase);\nif (!validKeys.Contains(request.Key))\n    throw new ArgumentException($\"Backup key '{request.Key}' not found.\");","typeGuard":"static bool IsValidBackupKey(string key, IReadOnlyList<IpcCloudBackupEntry> entries) =>\n    entries.Any(e => e.Key.Equals(key, StringComparison.OrdinalIgnoreCase));","tryCatchPattern":"try { await IpcBackupApi.DownloadCloudBackupAsync(request); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"was not found\"))\n{ /* key is wrong; re-list and pick a valid one */ }","preventionTips":["Populate key selectors from ListCloudBackupsAsync results.","Prefer the current-machine key when restoring on the same device.","Re-create a backup if the machine/user identity changed."],"tags":["github","backup","gist","restore","validation","ipc"],"backgroundTag":null,"analyzedSha":"9b1d7d0eab91620fc15c86b36676532095936ae3","analyzedAt":"2026-08-13T12:19:18.278Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}