{"record":{"id":"1c16c5a3ea1e75e9","repo":"Devolutions/UniGetUI","slug":"the-maintenance-command-exited-with-code-process","errorCode":null,"errorMessage":"The maintenance command exited with code {process.ExitCode}.","messagePattern":"The maintenance command exited with code (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/UniGetUI.Interface.IpcApi/IpcManagerMaintenanceApi.cs","lineNumber":336,"sourceCode":"        bool runAsAdmin = false\n    )\n    {\n        using Process process = new()\n        {\n            StartInfo = new ProcessStartInfo\n            {\n                FileName = fileName,\n                Arguments = arguments,\n                UseShellExecute = runAsAdmin,\n                Verb = runAsAdmin ? \"runas\" : string.Empty,\n                CreateNoWindow = !runAsAdmin,\n            },\n        };\n        process.Start();\n        await process.WaitForExitAsync();\n        if (process.ExitCode != 0)\n        {\n            throw new InvalidOperationException(\n                $\"The maintenance command exited with code {process.ExitCode}.\"\n            );\n        }\n    }\n\n    private static void EnsureConfirmed(IpcManagerMaintenanceRequest request, string action)\n    {\n        if (!request.Confirm)\n        {\n            throw new InvalidOperationException(\n                $\"The manager action \\\"{action}\\\" requires confirm=true.\"\n            );\n        }\n    }\n\n    private static void EnsureManager(IPackageManager manager, string expectedName)\n    {\n        if (!manager.Name.Equals(expectedName, StringComparison.OrdinalIgnoreCase))","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/Devolutions/UniGetUI/blob/9b1d7d0eab91620fc15c86b36676532095936ae3/src/UniGetUI.Interface.IpcApi/IpcManagerMaintenanceApi.cs#L318-L354","documentation":"Thrown by RunWindowsProcessAsync after a spawned maintenance subprocess (PowerShell 5 running a WinGet repair, Scoop install/uninstall, or Scoop cleanup script) exits with a non-zero ExitCode. The maintenance pipeline shells out to external CLI tools and treats any non-zero return as a hard failure, wrapping the numeric code in an InvalidOperationException.","triggerScenarios":"Calling IpcManagerMaintenanceApi.RunActionAsync with action 'repair-winget', 'install-scoop', 'uninstall-scoop', or 'cleanup-scoop' where the underlying PowerShell process returns non-zero. For cleanup-scoop specifically, manager.Status.ExecutablePath must be set first or a different error fires; if it is set but scoop cleanup exits non-zero, this error fires.","commonSituations":"WinGet repair fails because App Installer is corrupt or PowerShell execution policy blocks the inline script. Scoop install fails due to network issues or restricted environment. Scoop cleanup fails when a bucket is stale or the global scope requires admin elevation that was denied by UAC. The runAsAdmin=true path uses 'runas' Verb, so a UAC prompt declined by the user would cause the process to exit non-zero.","solutions":["Check the exit code in the exception message — a UAC denial typically returns code 1223, while execution-policy issues return 1.","For Scoop actions, first call GetMaintenanceInfo to confirm Ready=true and ExecutablePath is populated.","Run the same PowerShell command manually in an elevated shell to see the real error output before the process exits.","For repair-winget, verify App Installer (Microsoft.DesktopAppInstaller) is installed and not corrupt before retrying."],"exampleFix":"// before — calling cleanup on an unready Scoop manager\nawait IpcManagerMaintenanceApi.RunActionAsync(new IpcManagerMaintenanceRequest {\n    ManagerName = \"Scoop\", Action = \"cleanup-scoop\", Confirm = true\n});\n// after — verify readiness first\nvar info = IpcManagerMaintenanceApi.GetMaintenanceInfo(\"Scoop\");\nif (!info.Ready)\n    throw new InvalidOperationException(\"Scoop is not ready; install it first.\");\nawait IpcManagerMaintenanceApi.RunActionAsync(new IpcManagerMaintenanceRequest {\n    ManagerName = \"Scoop\", Action = \"cleanup-scoop\", Confirm = true\n});","handlingStrategy":"try-catch","validationCode":"var info = IpcManagerMaintenanceApi.GetMaintenanceInfo(request.ManagerName);\nif (!info.Ready && request.Action is \"cleanup-scoop\")\n    throw new InvalidOperationException(\"Manager is not ready for this action.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await IpcManagerMaintenanceApi.RunActionAsync(request);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"exited with code\"))\n{\n    logger.LogError(\"Maintenance command failed: {Message}\", ex.Message);\n    // Surface the exit code to the user for manual diagnosis\n}","preventionTips":["Verify manager readiness via GetMaintenanceInfo before invoking destructive actions.","Run the underlying PowerShell command manually in an elevated shell to diagnose exit codes.","Log the exit code from the exception message for post-mortem analysis."],"tags":["process","maintenance","ipc","powershell","windows"],"backgroundTag":null,"analyzedSha":"9b1d7d0eab91620fc15c86b36676532095936ae3","analyzedAt":"2026-08-13T12:19:18.278Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}