{"record":{"id":"893fe9e75f4d3b9d","repo":"microsoft/aspire","slug":"rad-credential-register-failed-with-exit-code-process","errorCode":null,"errorMessage":"rad credential register failed with exit code {process.ExitCode}: {stderr.ToString().Trim()}","messagePattern":"rad credential register failed with exit code (.+?): (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Radius/Publishing/RadCredentialRegisterStep.cs","lineNumber":330,"sourceCode":"                logger.LogWarning(\"Cancellation requested — terminating rad credential register process.\");\n                try\n                {\n                    process.Kill(entireProcessTree: true);\n                }\n                catch (InvalidOperationException)\n                {\n                    // Race: the process exited between the HasExited check and Kill. Nothing to do.\n                }\n            }\n\n            throw;\n        }\n\n        if (process.ExitCode != 0)\n        {\n            var msg = $\"rad credential register failed with exit code {process.ExitCode}: {stderr.ToString().Trim()}\";\n            logger.LogError(\"{Message}\", msg);\n            throw new InvalidOperationException(msg);\n        }\n    }\n\n    internal static IReadOnlyList<string> RedactSecretArgs(\n        IReadOnlyList<string> args, HashSet<string> secretFlags)\n    {\n        var result = new List<string>(args.Count);\n        for (var i = 0; i < args.Count; i++)\n        {\n            result.Add(args[i]);\n            if (secretFlags.Contains(args[i]) && i + 1 < args.Count)\n            {\n                result.Add(\"***\");\n                i++;\n            }\n        }\n        return result;\n    }","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Radius/Publishing/RadCredentialRegisterStep.cs#L312-L348","documentation":"After running the `rad credential register` CLI process, a non-zero exit code means Radius rejected the credential registration. The step logs the combined stderr and throws an InvalidOperationException containing the exit code and stderr text.","triggerScenarios":"Executing ExecuteAsync on RadCredentialRegisterStep when the rad CLI exits non-zero, e.g. the Radius environment/context is not initialized, the credential payload is invalid, or authentication to the control plane fails.","commonSituations":"rad CLI not logged in or pointed at the wrong Radius context; credential secret file malformed or expired; Kubernetes cluster / Radius control plane unreachable; version mismatch between rad CLI and installed Radius.","solutions":["Read the stderr text in the message; fix the underlying rad error (wrong context, auth failure, malformed credential).","Run `rad env list` / `rad credential list` manually to verify the CLI can reach the intended Radius installation.","Re-login or refresh credentials (`az login`, kubeconfig) and re-run the publish/deploy.","Ensure the installed rad CLI version matches your Radius control plane version."],"exampleFix":"// before (shell)\nrad credential register azure --from-env-file stale-creds.json\n// fails: exit code 1, 'unable to connect to control plane'\n\n// after (shell)\nrad env switch my-radius-env && az login && rad credential register azure --from-env-file creds.json","handlingStrategy":"try-catch","validationCode":"// Pre-flight: verify the rad CLI can reach the control plane before publishing\nvar psi = new ProcessStartInfo(\"rad\", \"env list\") { RedirectStandardError = true };\nusing var p = Process.Start(psi)!;\nawait p.WaitForExitAsync();\nif (p.ExitCode != 0) throw new InvalidOperationException($\"rad CLI pre-flight failed: {await p.StandardError.ReadToEndAsync()}\");","typeGuard":null,"tryCatchPattern":"try { await publishOperation.ExecuteAsync(ct); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"rad credential register failed\"))\n{\n    logger.LogError(ex, \"Credential registration failed; check rad context, login state, and credential file contents.\");\n}","preventionTips":["Run `rad env list` before publishing to confirm CLI/control-plane connectivity","Keep the rad CLI version matched to the installed Radius version","Validate credential files (az login state, kubeconfig, secret file format) before publish","Inspect the stderr in the error message first — it names the exact rad failure"],"tags":["radius","cli","process-exit-code","credentials","azure"],"backgroundTag":"command-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}