Skip to content

Commit

Permalink
Reinstate previous error messages of preflight failures
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh committed Sep 22, 2023
1 parent 90917d4 commit bf41bf3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 6 additions & 2 deletions cmd/kots/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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,
}
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/kots/cli/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
})
Expand All @@ -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}",
Expand All @@ -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"))
})
Expand All @@ -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() {
Expand Down

0 comments on commit bf41bf3

Please sign in to comment.