diff --git a/pkg/action/uninstall.go b/pkg/action/uninstall.go index 40d82243e..55beb4e82 100644 --- a/pkg/action/uninstall.go +++ b/pkg/action/uninstall.go @@ -47,6 +47,11 @@ type Uninstall struct { Description string } +type uninstallError struct { + error + uninstallErrors []error +} + // NewUninstall creates a new Uninstall object with the given configuration. func NewUninstall(cfg *Configuration) *Uninstall { return &Uninstall{ @@ -122,7 +127,7 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error) deletedResources, kept, errs := u.deleteRelease(rel) if errs != nil { u.cfg.Log("uninstall: Failed to delete release: %s", errs) - return nil, errors.Errorf("failed to delete release: %s", name) + return nil, uninstallError{error: errors.Errorf("failed to delete release: %s", name), uninstallErrors: errs} } if kept != "" { @@ -160,7 +165,7 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error) // Return the errors that occurred while deleting the release, if any if len(errs) > 0 { - return res, errors.Errorf("uninstallation completed with %d error(s): %s", len(errs), joinErrors(errs)) + return res, uninstallError{error: errors.Errorf("uninstallation completed with %d error(s): %s", len(errs), joinErrors(errs)), uninstallErrors: errs} } return res, nil @@ -171,7 +176,7 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error) } if len(errs) > 0 { - return res, errors.Errorf("uninstallation completed with %d error(s): %s", len(errs), joinErrors(errs)) + return res, uninstallError{error: errors.Errorf("uninstallation completed with %d error(s): %s", len(errs), joinErrors(errs)), uninstallErrors: errs} } return res, nil } diff --git a/pkg/action/uninstall_test.go b/pkg/action/uninstall_test.go index 869ffb8c7..6fff04d98 100644 --- a/pkg/action/uninstall_test.go +++ b/pkg/action/uninstall_test.go @@ -138,3 +138,43 @@ func TestUninstallRelease_Cascade(t *testing.T) { is.Error(err) is.Contains(err.Error(), "failed to delete release: come-fail-away") } + +func TestUninstallRelease_ReturnsAllErrors(t *testing.T) { + is := assert.New(t) + + unAction := uninstallAction(t) + unAction.DisableHooks = true + unAction.DryRun = false + unAction.Wait = false + unAction.DeletionPropagation = "foreground" + + rel := releaseStub() + rel.Name = "come-fail-away" + rel.Manifest = `{ + "apiVersion": "v1", + "kind": "Secret", + "metadata": { + "name": "secret" + }, + "type": "Opaque", + "data": { + "password": "password" + } + }` + unAction.cfg.Releases.Create(rel) + failer := unAction.cfg.KubeClient.(*kubefake.FailingKubeClient) + failer.DeleteWithPropagationError = fmt.Errorf("uninstall error") + failer.BuildDummy = true + unAction.cfg.KubeClient = failer + + _, err := unAction.Run(rel.Name) + is.Error(err) + is.Contains(err.Error(), "failed to delete release: come-fail-away") + uninstallErr, ok := err.(uninstallError) + if !ok { + t.Errorf("Expected returned error to be of type uninstallError: got %v(%T)", err, err) + } + + is.Len(uninstallErr.uninstallErrors, 1) + is.Contains(uninstallErr.uninstallErrors[0].Error(), "uninstall error") +}