{"record":{"id":"2d8c484f8396d5b0","repo":"microsoft/aspire","slug":"helm-uninstall-failed-with-exit-code-exitcode","errorCode":null,"errorMessage":"helm uninstall failed with exit code {exitCode}","messagePattern":"helm uninstall failed with exit code (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/Deployment/HelmDeploymentEngine.cs","lineNumber":637,"sourceCode":"                // state cleanup failed. Keep retries idempotent without masking unrelated Helm errors.\n                var arguments = $\"uninstall {releaseName} --namespace {@namespace} --ignore-not-found\";\n\n                if (environment.KubeConfigPath is not null)\n                {\n                    arguments += $\" --kubeconfig \\\"{environment.KubeConfigPath}\\\"\";\n                }\n\n                context.Logger.LogDebug(\"Running helm {Arguments}\", arguments);\n\n                var exitCode = await helmRunner.RunAsync(\n                    arguments,\n                    onOutputData: output => context.Logger.LogDebug(\"helm (stdout): {Output}\", output),\n                    onErrorData: error => context.Logger.LogDebug(\"helm (stderr): {Error}\", error),\n                    cancellationToken: context.CancellationToken).ConfigureAwait(false);\n\n                if (exitCode != 0)\n                {\n                    throw new InvalidOperationException($\"helm uninstall failed with exit code {exitCode}\");\n                }\n                else\n                {\n                    await uninstallTask.CompleteAsync(\n                        new MarkdownString($\"Helm release **{releaseName}** uninstalled from namespace **{@namespace}**\"),\n                        CompletionState.Completed,\n                        context.CancellationToken).ConfigureAwait(false);\n                }\n            }\n            catch (Exception ex) when (ex is not OperationCanceledException)\n            {\n                await uninstallTask.CompleteAsync(\n                    $\"Helm uninstall failed: {ex.Message}\",\n                    CompletionState.CompletedWithError,\n                    context.CancellationToken).ConfigureAwait(false);\n                throw;\n            }\n        }","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/Deployment/HelmDeploymentEngine.cs#L619-L655","documentation":"The 'helm uninstall' process that removes the release during destroy exited with a non-zero exit code, so the destroy step throws. Unlike deploy, no stderr is embedded in the message; helm's stderr is only logged at Debug level by the engine.","triggerScenarios":"HelmUninstallAsync runs helm uninstall for the release/namespace and the process exits non-zero - e.g. the release no longer exists (already uninstalled), the cluster/context is unreachable, or the Kubernetes API rejected the delete.","commonSituations":"Running destroy twice (release already gone), kubeconfig credentials expired between deploy and destroy, cluster or namespace deleted out-of-band, or finalizer/termination stalls causing uninstall timeouts.","solutions":["Run 'helm uninstall <release> -n <namespace>' manually with the same kubeconfig to see the real helm error.","If the release is already gone, remove the stale deployment state section ('Helm:<environment>') or treat destroy as complete - the failure is then only bookkeeping.","Check cluster connectivity and credentials (kubectl config current-context, kubectl get ns).","If resources are stuck terminating due to finalizers, patch/remove the finalizers or wait for termination, then retry destroy."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before destroy, confirm the release still exists:\n// helm status <release> -n <namespace>   (non-zero => release already gone; skip uninstall)","typeGuard":null,"tryCatchPattern":"try\n{\n    await deploymentEngine.DestroyAsync(context);\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"helm uninstall failed\"))\n{\n    // helm's real error is only at Debug log level; re-run with debug logging or run helm uninstall manually\n    logger.LogError(ex, \"Helm uninstall failed; check release/namespace state\");\n    throw;\n}","preventionTips":["Check 'helm list -n <namespace>' before destroy to detect already-uninstalled or externally deleted releases.","Use the same kubeconfig/context for deploy and destroy so credentials don't expire mid-lifecycle.","Watch for stuck resources with finalizers; resolve them before retrying uninstall.","Turn on Debug logging during destroy - this error hides helm's stderr from the message."],"tags":["kubernetes","helm","destroy","process-exit-code"],"backgroundTag":"command-failed","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}