From bf41bf3ec76288fe7fd237cd12c7d2bb0546be2a Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Fri, 22 Sep 2023 10:05:07 +0100 Subject: [PATCH] Reinstate previous error messages of preflight failures --- cmd/kots/cli/install.go | 8 ++++++-- cmd/kots/cli/install_test.go | 14 +++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cmd/kots/cli/install.go b/cmd/kots/cli/install.go index 4582dc4d25..697f248ac8 100644 --- a/cmd/kots/cli/install.go +++ b/cmd/kots/cli/install.go @@ -1016,14 +1016,15 @@ func checkPreflightsComplete(response *handlers.GetPreflightResultResponse) (boo } type preflightError struct { + Msg string Results []*preflight.UploadPreflightResult } func (e preflightError) Error() string { - return "preflight checks have warnings or errors" + return e.Msg } -func (e preflightError) Unwrap() error { return fmt.Errorf("preflight checks have warnings or errors") } +func (e preflightError) Unwrap() error { return fmt.Errorf(e.Msg) } func checkPreflightResults(response *handlers.GetPreflightResultResponse) (bool, error) { if response.PreflightResult.Result == "" { @@ -1048,17 +1049,20 @@ func checkPreflightResults(response *handlers.GetPreflightResultResponse) (bool, if isWarn && isFail { return false, preflightError{ + Msg: "There are preflight check failures and warnings for the application. The app was not deployed.", Results: results.Results, } } if isWarn { return false, preflightError{ + Msg: "There are preflight check warnings for the application. The app was not deployed.", Results: results.Results, } } if isFail { return false, preflightError{ + Msg: "There are preflight check failures for the application. The app was not deployed.", Results: results.Results, } } diff --git a/cmd/kots/cli/install_test.go b/cmd/kots/cli/install_test.go index 19ad35b4c3..7ff8e06adc 100644 --- a/cmd/kots/cli/install_test.go +++ b/cmd/kots/cli/install_test.go @@ -223,7 +223,7 @@ var _ = Describe("Install", func() { }) It("returns an error if the preflight collection results cannot be parsed", func() { - invalidPreflightCollection, err := json.Marshal(handlers.GetPreflightResultResponse{ + invalidPreflightCollection, _ := json.Marshal(handlers.GetPreflightResultResponse{ PreflightProgress: `{invalid: json}`, PreflightResult: preflighttypes.PreflightResult{}, }) @@ -239,13 +239,13 @@ var _ = Describe("Install", func() { ), ) - err = ValidatePreflightStatus(validDeployOptions, authSlug, server.URL()) + err := ValidatePreflightStatus(validDeployOptions, authSlug, server.URL()) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("failed to unmarshal collect progress for preflights")) }) It("returns an error if the upload preflight results are invalid", func() { - invalidUploadPreflightResponse, err := json.Marshal(handlers.GetPreflightResultResponse{ + invalidUploadPreflightResponse, _ := json.Marshal(handlers.GetPreflightResultResponse{ PreflightProgress: "", PreflightResult: preflighttypes.PreflightResult{ Result: "{invalid: json}", @@ -262,7 +262,7 @@ var _ = Describe("Install", func() { ), ) - err = ValidatePreflightStatus(validDeployOptions, authSlug, server.URL()) + err := ValidatePreflightStatus(validDeployOptions, authSlug, server.URL()) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("failed to unmarshal upload preflight results")) }) @@ -286,9 +286,9 @@ var _ = Describe("Install", func() { Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring(expectedErr)) }, - Entry("warnings and failures", true, true, "Preflight checks have warnings or errors"), - Entry("warnings only", false, true, "Preflight checks have warnings or errors"), - Entry("failures only", true, false, "Preflight checks have warnings or errors"), + Entry("warnings and failures", true, true, "There are preflight check failures and warnings for the application"), + Entry("warnings only", false, true, "There are preflight check warnings for the application"), + Entry("failures only", true, false, "There are preflight check failures for the application"), ) It("does not return an error if there are no warnings and failures", func() {