{"record":{"id":"bd3202b28db94b31","repo":"Devolutions/UniGetUI","slug":"the-backup-key-is-required","errorCode":null,"errorMessage":"The backup key is required.","messagePattern":"The backup key is required\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"src/UniGetUI.Interface.IpcApi/IpcBackupApi.cs","lineNumber":561,"sourceCode":"            isPublic: false,\n            new Dictionary<string, string> { [\"- UniGetUI Package Backups\"] = ReadMeContents }\n        );\n    }\n\n    private static string BuildGistFileKey()\n    {\n        string deviceUser = (Environment.MachineName + \"\\\\\" + Environment.UserName).Replace(\n            \" \",\n            string.Empty\n        );\n        return PackageBackupStartingKey + \" \" + deviceUser;\n    }\n\n    private static string ValidateBackupKey(string key)\n    {\n        if (string.IsNullOrWhiteSpace(key))\n        {\n            throw new InvalidOperationException(\"The backup key is required.\");\n        }\n\n        return key;\n    }\n\n    private static PendingGitHubDeviceFlow GetPendingGitHubDeviceFlow()\n    {\n        lock (GitHubAuthLock)\n        {\n            return _pendingGitHubDeviceFlow\n                ?? throw new InvalidOperationException(\n                    \"No GitHub device flow is pending. Start sign-in first.\"\n                );\n        }\n    }\n\n    private static void ClearPendingGitHubDeviceFlow()\n    {","sourceCodeStart":543,"sourceCodeEnd":579,"githubUrl":"https://github.com/Devolutions/UniGetUI/blob/9b1d7d0eab91620fc15c86b36676532095936ae3/src/UniGetUI.Interface.IpcApi/IpcBackupApi.cs#L543-L579","documentation":"ValidateBackupKey is called by DownloadCloudBackupAsync and RestoreCloudBackupAsync on request.Key before doing any work. If the key is null, empty, or whitespace, it throws InvalidOperationException. The key identifies a specific machine/device backup within the gist, so a blank value is a client error.","triggerScenarios":"An IPC client sends a DownloadCloudBackupAsync or RestoreCloudBackupAsync request with Key unset (null), empty string, or whitespace. This is purely a client-side validation failure before any GitHub API call.","commonSituations":"The client omitted the Key field in the request JSON. The key was read from a config that had no value. A UI form submitted without selecting a backup entry. A programmatic caller forgot to populate the key.","solutions":["Provide a non-empty Key in the IpcCloudBackupRequest, obtained from ListCloudBackupsAsync.","Validate the key client-side before sending the request.","Default to the current machine's key (BuildGistFileKey / CurrentMachineBackupKey from GetStatusAsync) if the user did not pick one."],"exampleFix":"// before: empty key\nawait IpcBackupApi.DownloadCloudBackupAsync(new IpcCloudBackupRequest { Key = \"\" });\n// after: use the current machine key or a listed entry\nvar status = await IpcBackupApi.GetStatusAsync();\nawait IpcBackupApi.DownloadCloudBackupAsync(new IpcCloudBackupRequest { Key = status.CurrentMachineBackupKey });","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(request.Key))\n{\n    var status = await IpcBackupApi.GetStatusAsync();\n    request.Key = status.CurrentMachineBackupKey;\n}","typeGuard":"static bool HasBackupKey(string? key) => !string.IsNullOrWhiteSpace(key);","tryCatchPattern":"try { await IpcBackupApi.DownloadCloudBackupAsync(request); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"backup key is required\"))\n{ /* client must supply a key */ }","preventionTips":["Always populate Key, defaulting to CurrentMachineBackupKey from GetStatusAsync.","Validate the key client-side before sending the IPC request.","Never submit an empty/null key."],"tags":["backup","validation","ipc","client-error"],"backgroundTag":null,"analyzedSha":"9b1d7d0eab91620fc15c86b36676532095936ae3","analyzedAt":"2026-08-13T12:19:18.278Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}