@@ -2,6 +2,7 @@ package operation
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "io"
78 "os"
@@ -73,10 +74,10 @@ func (p *AppPushOperation) pushWithStrategyApp(ctx context.Context, space *resou
7374
7475func (p * AppPushOperation ) pushBlueGreenApp (ctx context.Context , space * resource.Space , manifest * AppManifest , zipFile io.Reader ) (* resource.App , error ) {
7576 originalApp , err := p .findApp (ctx , manifest .Name , space )
76- if err != nil && err != client .ErrExactlyOneResultNotReturned {
77+ if err != nil && ! errors . Is ( err , client .ErrExactlyOneResultNotReturned ) {
7778 return nil , err
7879 }
79- if err == client .ErrExactlyOneResultNotReturned || originalApp .State != "STARTED" {
80+ if errors . Is ( err , client .ErrExactlyOneResultNotReturned ) || originalApp .State != "STARTED" {
8081 return p .pushApp (ctx , space , manifest , zipFile )
8182 }
8283
@@ -96,7 +97,7 @@ func (p *AppPushOperation) pushBlueGreenApp(ctx context.Context, space *resource
9697 Name : tempAppName ,
9798 })
9899 if err != nil {
99- return nil , fmt .Errorf ("failed to update app name failed with: %s " , err . Error () )
100+ return nil , fmt .Errorf ("failed to update app name failed with: %w " , err )
100101 }
101102
102103 // Apply the manifest
@@ -107,23 +108,23 @@ func (p *AppPushOperation) pushBlueGreenApp(ctx context.Context, space *resource
107108 Name : originalApp .Name ,
108109 })
109110 if err != nil {
110- return nil , fmt .Errorf ("failed to update app name back to original name: failed with %s " , err . Error () )
111+ return nil , fmt .Errorf ("failed to update app name back to original name: failed with %w " , err )
111112 }
112- return nil , fmt .Errorf ("blue green deployment failed with: %s " , err . Error () )
113+ return nil , fmt .Errorf ("blue green deployment failed with: %w " , err )
113114 }
114115 if newApp .State == "STARTED" {
115116 err = p .gracefulDeletion (ctx , originalApp )
116117 return newApp , err
117118 }
118- return newApp , fmt .Errorf ("failed to verify application start: %s " , err . Error () )
119+ return newApp , fmt .Errorf ("failed to verify application start: %w " , err )
119120}
120121
121122func (p * AppPushOperation ) pushRollingApp (ctx context.Context , space * resource.Space , manifest * AppManifest , zipFile io.Reader ) (* resource.App , error ) {
122123 originalApp , err := p .findApp (ctx , manifest .Name , space )
123- if err != nil && err != client .ErrExactlyOneResultNotReturned {
124+ if err != nil && ! errors . Is ( err , client .ErrExactlyOneResultNotReturned ) {
124125 return nil , err
125126 }
126- if err == client .ErrExactlyOneResultNotReturned || originalApp .State != "STARTED" {
127+ if errors . Is ( err , client .ErrExactlyOneResultNotReturned ) || originalApp .State != "STARTED" {
127128 return p .pushApp (ctx , space , manifest , zipFile )
128129 }
129130 // Get the fallback revision in case of rollback
@@ -151,7 +152,7 @@ func (p *AppPushOperation) pushRollingApp(ctx context.Context, space *resource.S
151152
152153 deployment , err := p .createNewDeployment (ctx , originalApp , droplet )
153154 if err != nil {
154- return nil , fmt .Errorf ("failed to deploy with: %s " , err . Error () )
155+ return nil , fmt .Errorf ("failed to deploy with: %w " , err )
155156 }
156157 // In case application crashed due to new deployment, deployment will be stuck with value "ACTIVE" and reason "DEPLOYING"
157158 // This will be considered as deployment failed after timeout
@@ -160,18 +161,18 @@ func (p *AppPushOperation) pushRollingApp(ctx context.Context, space *resource.S
160161 // Check the app state if app not started or deployment failed rollback the deployment
161162 originalApp , err = p .findApp (ctx , manifest .Name , space )
162163 if err != nil {
163- return nil , fmt .Errorf ("failed to verify application status with: %s " , err . Error () )
164+ return nil , fmt .Errorf ("failed to verify application status with: %w " , err )
164165 }
165166 if originalApp .State != "STARTED" || depPollErr != nil {
166167 rollBackDeployment , rollBackErr := p .rollBackDeployment (ctx , originalApp , fallbackRevision )
167168 if rollBackErr != nil {
168- return nil , fmt .Errorf ("failed to confirm rollback deployment with: %s " , rollBackErr . Error () )
169+ return nil , fmt .Errorf ("failed to confirm rollback deployment with: %w " , rollBackErr )
169170 }
170171 depRollPollErr := p .waitForDeployment (ctx , rollBackDeployment .GUID , * manifest .Instances )
171172 if depRollPollErr != nil {
172- return nil , fmt .Errorf ("failed to deploy with: %s \n failed to confirm roll back to last deployment with: %s " , depPollErr . Error () , depRollPollErr . Error () )
173+ return nil , fmt .Errorf ("failed to deploy with: %w \n failed to confirm roll back to last deployment with: %w " , depPollErr , depRollPollErr )
173174 }
174- return nil , fmt .Errorf ("failed to deploy with: %s \n rolled back to last deployment" , depPollErr . Error () )
175+ return nil , fmt .Errorf ("failed to deploy with: %w \n rolled back to last deployment" , depPollErr )
175176 }
176177
177178 return originalApp , nil
@@ -232,7 +233,7 @@ func (p *AppPushOperation) rollBackDeployment(ctx context.Context, originalApp *
232233func (p * AppPushOperation ) gracefulDeletion (ctx context.Context , app * resource.App ) error {
233234 app , err := p .client .Applications .Stop (ctx , app .GUID )
234235 if err != nil {
235- return fmt .Errorf ("failed to stop the application with: %s " , err . Error () )
236+ return fmt .Errorf ("failed to stop the application with: %w " , err )
236237 }
237238 jobId , err := p .client .Applications .Delete (ctx , app .GUID )
238239 if err != nil {
0 commit comments