Skip to content

Commit

Permalink
Handle ProcessNotFoundError in cf apps
Browse files Browse the repository at this point in the history
As a user calls `cf apps` in a large space it might happen that a app
was deleted while the CLI is putting all the different information (processes, stats & routes) together.
This leads to a failing `cf apps` command.
This change prevents this by catching `ProcessNotFoundError` errors and returning `nil` instead.
Related to #2734
  • Loading branch information
johha committed Feb 19, 2024
1 parent 2d9e6ec commit 142a0d3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
8 changes: 7 additions & 1 deletion actor/v7action/application_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v7action

import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/util/batcher"
Expand Down Expand Up @@ -141,7 +142,12 @@ func (actor Actor) getProcessSummariesForApps(apps []resources.Application, proc
allWarnings = append(allWarnings, Warnings(warnings)...)

if err != nil {
return allWarnings, err
switch err.(type) {
case ccerror.ProcessNotFoundError, ccerror.InstanceNotFoundError:
continue
default:
return allWarnings, err
}
}

var instanceDetails []ProcessInstance
Expand Down
50 changes: 50 additions & 0 deletions actor/v7action/application_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,56 @@ var _ = Describe("Application Summary Actions", func() {
Expect(fakeCloudControllerClient.GetProcessInstancesCallCount()).To(Equal(0))
})
})

When("an application is deleted in between", func() {

BeforeEach(func() {
fakeCloudControllerClient.GetApplicationsReturns(
[]resources.Application{
{
Name: "some-app-name",
GUID: "some-app-guid",
State: constant.ApplicationStarted,
},
},
nil,
nil,
)

fakeCloudControllerClient.GetProcessesReturns(
[]resources.Process{
{
GUID: "some-process-web-guid",
Type: "web",
Command: *types.NewFilteredString("[Redacted Value]"),
MemoryInMB: types.NullUint64{Value: 64, IsSet: true},
AppGUID: "some-app-guid",
},
},
nil,
nil,
)

fakeCloudControllerClient.GetProcessInstancesReturns(nil, nil, ccerror.ProcessNotFoundError{})
})

It("does not fail and has empty ProcessSummaries & Routes", func() {
Expect(executeErr).ToNot(HaveOccurred())

Expect(summaries).To(Equal([]ApplicationSummary{
{
Application: resources.Application{
Name: "some-app-name",
GUID: "some-app-guid",
State: constant.ApplicationStarted,
},
ProcessSummaries: nil,
Routes: nil,
},
}))

})
})
})

Describe("GetDetailedAppSummary", func() {
Expand Down

0 comments on commit 142a0d3

Please sign in to comment.