Skip to content

Commit

Permalink
Merge branch 'v7'
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalmerpivotal and Lisa Burns committed Oct 30, 2020
2 parents 50a8595 + 6dfd8aa commit fa06434
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
15 changes: 15 additions & 0 deletions api/cloudcontroller/ccerror/job_failed_no_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ccerror

import (
"fmt"
)

// V3JobFailedError represents a failed Cloud Controller Job. It wraps the error
// returned back from the Cloud Controller.
type JobFailedNoErrorError struct {
JobGUID string
}

func (e JobFailedNoErrorError) Error() string {
return fmt.Sprintf("Job (%s) failed with no error. This is unexpected, contact your operator for details.", e.JobGUID)
}
10 changes: 8 additions & 2 deletions api/cloudcontroller/ccv3/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ func (client *Client) PollJobForState(jobURL JobURL, state constant.JobState) (W
}

if job.HasFailed() {
firstError := job.Errors()[0]
return allWarnings, firstError
if len(job.Errors()) > 0 {
firstError := job.Errors()[0]
return allWarnings, firstError
} else {
return allWarnings, ccerror.JobFailedNoErrorError{
JobGUID: job.GUID,
}
}
}

if job.IsComplete() {
Expand Down
45 changes: 39 additions & 6 deletions api/cloudcontroller/ccv3/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,49 @@ var _ = Describe("Job", func() {
BeforeEach(func() {
appendHandler("PROCESSING", Warnings{"warning-1"})
appendHandler("PROCESSING", Warnings{"warning-2", "warning-3"})
appendFailureHandler("some-message", constant.JobErrorCodeBuildpackAlreadyExistsForStack, Warnings{"warning-4"})
})
Context("with an error", func() {
BeforeEach(func() {
appendFailureHandler("some-message", constant.JobErrorCodeBuildpackAlreadyExistsForStack, Warnings{"warning-4"})
})
It("returns the first error", func() {
Expect(executeErr).To(MatchError(ccerror.BuildpackAlreadyExistsForStackError{
Message: "some-message",
}))
Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4"))
})
})
Context("without an error", func() {
BeforeEach(func() {
server.AppendHandlers(
CombineHandlers(
VerifyRequest(http.MethodGet, "/some-job-location"),
RespondWith(http.StatusOK, `{
"guid": "job-guid",
"created_at": "2016-06-08T16:41:27Z",
"updated_at": "2016-06-08T16:41:27Z",
"operation": "app.delete",
"state": "FAILED",
"errors": null,
"links": {
"self": {
"href": "/v3/jobs/job-guid"
}
}
}`, http.Header{"X-Cf-Warnings": []string{"warning-4"}}),
),
)
})

It("returns the first error", func() {
Expect(executeErr).To(MatchError(ccerror.BuildpackAlreadyExistsForStackError{
Message: "some-message",
}))
Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4"))
It("returns the JobFailedNoErrorError", func() {
Expect(executeErr).To(MatchError(ccerror.JobFailedNoErrorError{
JobGUID: "job-guid",
}))
Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4"))
})
})
})

}

itRespectsTimeouts := func() {
Expand Down
2 changes: 2 additions & 0 deletions command/translatableerror/convert_to_translatable_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ func ConvertToTranslatableError(err error) error {
return JobFailedError{JobGUID: e.JobGUID, Message: e.Detail}
case ccerror.JobTimeoutError:
return JobTimeoutError{JobGUID: e.JobGUID}
case ccerror.JobFailedNoErrorError:
return JobFailedNoErrorError{JobGUID: e.JobGUID}
case ccerror.MultiError:
return MultiError{Messages: e.Details()}
case ccerror.UnprocessableEntityError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ var _ = Describe("ConvertToTranslatableError", func() {
ccerror.JobTimeoutError{JobGUID: "some-job-guid"},
JobTimeoutError{JobGUID: "some-job-guid"}),

Entry("ccerror.JobFailedNoErrorError -> JobFailedNoErrorError",
ccerror.JobFailedNoErrorError{JobGUID: "some-job-guid"},
JobFailedNoErrorError{JobGUID: "some-job-guid"}),

Entry("ccerror.MultiError -> MultiError",
ccerror.MultiError{ResponseCode: 418, Errors: []ccerror.V3Error{
{
Expand Down
17 changes: 17 additions & 0 deletions command/translatableerror/job_failed_no_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package translatableerror

// RevisionAmbiguousError is returned when multiple revisions with the same
// version are returned
type JobFailedNoErrorError struct {
JobGUID string
}

func (e JobFailedNoErrorError) Error() string {
return "Job {{.JobGUID}} failed with no error. This is unexpected, contact your operator for details."
}

func (e JobFailedNoErrorError) Translate(translate func(string, ...interface{}) string) string {
return translate(e.Error(), map[string]interface{}{
"JobGUID": e.JobGUID,
})
}

0 comments on commit fa06434

Please sign in to comment.