Skip to content

Commit c38276a

Browse files
authored
print app logs when fail to start or stop (#568)
1 parent beeba12 commit c38276a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

cloudfoundry/managers/v3appdeployers/runbinder.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (r RunBinder) BindServiceInstances(appDeploy AppDeploy) ([]resources.Servic
222222

223223
// WaitStart checks the state of each process instance
224224
func (r RunBinder) WaitStart(appDeploy AppDeploy) error {
225-
return common.PollingWithTimeout(func() (bool, error) {
225+
err := common.PollingWithTimeout(func() (bool, error) {
226226
process, _, err := r.client.GetApplicationProcessByType(appDeploy.App.GUID, constant.ProcessTypeWeb)
227227
if err != nil {
228228
return true, err
@@ -250,6 +250,10 @@ func (r RunBinder) WaitStart(appDeploy AppDeploy) error {
250250

251251
return false, nil
252252
}, 5*time.Second, appDeploy.StartTimeout)
253+
if err != nil {
254+
return r.processDeployErr(err, appDeploy)
255+
}
256+
return nil
253257
}
254258

255259
func (r RunBinder) WaitStaging(appDeploy AppDeploy) error {
@@ -348,13 +352,13 @@ func (r RunBinder) Start(appDeploy AppDeploy) (resources.Application, resources.
348352
}, 5*time.Second, appDeploy.StageTimeout)
349353

350354
if err != nil {
351-
return resources.Application{}, resources.Process{}, err
355+
return resources.Application{}, resources.Process{}, r.processDeployErr(err, appDeploy)
352356
}
353357

354358
// Poll staged package
355359
completedBuild, _, err := r.client.GetBuild(build.GUID)
356360
if err != nil {
357-
return resources.Application{}, resources.Process{}, err
361+
return resources.Application{}, resources.Process{}, r.processDeployErr(err, appDeploy)
358362
}
359363
dropletGUID := completedBuild.DropletGUID
360364

@@ -384,7 +388,7 @@ func (r RunBinder) Start(appDeploy AppDeploy) (resources.Application, resources.
384388

385389
scaledProcess, _, err := r.client.CreateApplicationProcessScale(appDeploy.App.GUID, processScaleInfo)
386390
if err != nil {
387-
return resources.Application{}, resources.Process{}, err
391+
return resources.Application{}, resources.Process{}, r.processDeployErr(err, appDeploy)
388392
}
389393

390394
// Process update info
@@ -397,7 +401,7 @@ func (r RunBinder) Start(appDeploy AppDeploy) (resources.Application, resources.
397401
HealthCheckInvocationTimeout: appDeploy.Process.HealthCheckInvocationTimeout,
398402
})
399403
if err != nil {
400-
return resources.Application{}, resources.Process{}, err
404+
return resources.Application{}, resources.Process{}, r.processDeployErr(err, appDeploy)
401405
}
402406
// If command = null or "", the command field in updatedProcess will be the default generated by buildpack
403407
// In that case, we don't set it in tfstate
@@ -408,12 +412,12 @@ func (r RunBinder) Start(appDeploy AppDeploy) (resources.Application, resources.
408412
// Start application
409413
_, _, err = r.client.UpdateApplicationStart(appDeploy.App.GUID)
410414
if err != nil {
411-
return resources.Application{}, resources.Process{}, err
415+
return resources.Application{}, resources.Process{}, r.processDeployErr(err, appDeploy)
412416
}
413417

414418
err = r.WaitStart(appDeploy)
415419
if err != nil {
416-
return resources.Application{}, resources.Process{}, r.processDeployErr(err, appDeploy)
420+
return resources.Application{}, resources.Process{}, err
417421
}
418422

419423
app, _, err := r.client.GetApplications(ccv3.Query{
@@ -430,7 +434,7 @@ func (r RunBinder) Start(appDeploy AppDeploy) (resources.Application, resources.
430434
func (r RunBinder) Stop(appDeploy AppDeploy) error {
431435
_, _, err := r.client.UpdateApplicationStop(appDeploy.App.GUID)
432436
if err != nil {
433-
return err
437+
return r.processDeployErr(err, appDeploy)
434438
}
435439

436440
return nil
@@ -456,5 +460,5 @@ func (r RunBinder) processDeployErr(origErr error, appDeploy AppDeploy) error {
456460
if err != nil {
457461
logs = fmt.Sprintf("Error occurred when recolting app %s logs: %s", appDeploy.App.Name, err.Error())
458462
}
459-
return fmt.Errorf("%s\n\nApp '%s' logs: \n%s", origErr.Error(), appDeploy.App.Name, logs)
463+
return fmt.Errorf("%s\n\nApp '%s' logs:\n%s", origErr.Error(), appDeploy.App.Name, logs)
460464
}

0 commit comments

Comments
 (0)