@@ -35,7 +35,7 @@ import (
35
35
func (b * Book ) Checkout (step string ) error {
36
36
// FIXME: keep vendor/ node_modules/ around before git clean, but them back as they will be updated the right way, less Internet traffic
37
37
// FIXME: if the checkout is to a later step, no need to remove the DB, we can just migrate it
38
- os .Chdir (b .Dir )
38
+ _ = os .Chdir (b .Dir )
39
39
step = strings .Replace (step , "." , "-" , - 1 )
40
40
tag := fmt .Sprintf ("step-%s" , step )
41
41
branch := "work-" + tag
@@ -80,21 +80,21 @@ func (b *Book) Checkout(step string) error {
80
80
81
81
printBanner ("<comment>[GIT]</> Removing Git ignored files (vendor, cache, ...)" , b .Debug )
82
82
if err := executeCommand ([]string {"git" , "clean" , "-d" , "-f" , "-x" }, b .Debug , false , nil ); err != nil {
83
- return err
83
+ return errors . WithStack ( err )
84
84
}
85
85
printBanner ("<comment>[GIT]</> Resetting Git staged files" , b .Debug )
86
86
if err := executeCommand ([]string {"git" , "reset" , "HEAD" , "." }, b .Debug , false , nil ); err != nil {
87
- return err
87
+ return errors . WithStack ( err )
88
88
}
89
89
printBanner ("<comment>[GIT]</> Removing un-tracked Git files" , b .Debug )
90
90
if err := executeCommand ([]string {"git" , "checkout" , "." }, b .Debug , false , nil ); err != nil {
91
- return err
91
+ return errors . WithStack ( err )
92
92
}
93
93
94
94
printBanner ("<comment>[WEB]</> Adding .env.local" , b .Debug )
95
95
emptyFile , err := os .Create (filepath .Join (b .Dir , ".env.local" ))
96
96
if err != nil {
97
- return err
97
+ return errors . WithStack ( err )
98
98
}
99
99
emptyFile .Close ()
100
100
if ! b .Debug {
@@ -110,40 +110,44 @@ func (b *Book) Checkout(step string) error {
110
110
printBanner ("<comment>[WEB]</> Stopping Docker Containers" , b .Debug )
111
111
if hasDocker {
112
112
if err := executeCommand (append (dockerComposeBin (), "down" , "--remove-orphans" ), b .Debug , false , nil ); err != nil {
113
- return err
113
+ return errors . WithStack ( err )
114
114
}
115
115
} else {
116
116
terminal .Println ("Skipped for this step" )
117
117
}
118
118
119
119
printBanner ("<comment>[WEB]</> Stopping the Local Web Server" , b .Debug )
120
- executeCommand ([]string {"symfony" , "server:stop" }, b .Debug , true , nil )
120
+ if err := executeCommand ([]string {"symfony" , "server:stop" }, b .Debug , true , nil ); err != nil {
121
+ return errors .Wrap (err , "cannot stop the symfony server" )
122
+ }
121
123
122
124
printBanner ("<comment>[WEB]</> Stopping the Platform.sh tunnel" , b .Debug )
123
125
if err := executeCommand ([]string {"symfony" , "tunnel:close" , "-y" }, b .Debug , true , nil ); err != nil {
124
- return err
126
+ return errors . WithStack ( err )
125
127
}
126
128
127
129
printBanner ("<comment>[GIT]</> Checking out the step" , b .Debug )
128
130
if err := executeCommand ([]string {"git" , "checkout" , "-B" , branch , tag }, b .Debug , false , nil ); err != nil {
129
- return err
131
+ return errors . WithStack ( err )
130
132
}
131
133
132
134
printBanner ("<comment>[SPA]</> Stopping the Local Web Server" , b .Debug )
133
135
if _ , err := os .Stat (filepath .Join (b .Dir , "spa" )); err == nil {
134
- executeCommand ([]string {"symfony" , "server:stop" , "--dir" , filepath .Join (b .Dir , "spa" )}, b .Debug , true , nil )
136
+ if err := executeCommand ([]string {"symfony" , "server:stop" , "--dir" , filepath .Join (b .Dir , "spa" )}, b .Debug , true , nil ); err != nil {
137
+ return errors .Wrap (err , "cannot stop the symfony server" )
138
+ }
135
139
} else {
136
140
terminal .Println ("Skipped for this step" )
137
141
}
138
142
139
143
printBanner ("<comment>[WEB]</> Installing Composer dependencies (might take some time)" , b .Debug )
140
144
if err := executeCommand ([]string {"symfony" , "composer" , "install" }, b .Debug , false , nil ); err != nil {
141
- return err
145
+ return errors . WithStack ( err )
142
146
}
143
147
144
148
printBanner ("<comment>[WEB]</> Adding .env.local" , b .Debug )
145
149
if emptyFile , err = os .Create (filepath .Join (b .Dir , ".env.local" )); err != nil {
146
- return err
150
+ return errors . WithStack ( err )
147
151
}
148
152
emptyFile .Close ()
149
153
if ! b .Debug {
@@ -153,7 +157,7 @@ func (b *Book) Checkout(step string) error {
153
157
printBanner ("<comment>[WEB]</> Starting Docker Compose" , b .Debug )
154
158
if hasDocker {
155
159
if err := executeCommand (append (dockerComposeBin (), "up" , "-d" ), b .Debug , false , nil ); err != nil {
156
- return err
160
+ return errors . WithStack ( err )
157
161
}
158
162
printBanner ("<comment>[WEB]</> Waiting for the Containers to be ready" , b .Debug )
159
163
if _ , err := os .Stat (filepath .Join (b .Dir , "src" , "MessageHandler" , "CommentMessageHandler.php" )); err == nil {
@@ -179,7 +183,7 @@ func (b *Book) Checkout(step string) error {
179
183
}
180
184
if hasMigrations {
181
185
if err := executeCommand ([]string {"symfony" , "console" , "doctrine:migrations:migrate" , "-n" }, b .Debug , false , nil ); err != nil {
182
- return err
186
+ return errors . WithStack ( err )
183
187
}
184
188
} else {
185
189
terminal .Println ("Skipped for this step" )
@@ -188,7 +192,7 @@ func (b *Book) Checkout(step string) error {
188
192
printBanner ("<comment>[WEB]</> Inserting Fixtures" , b .Debug )
189
193
if _ , err := os .Stat (filepath .Join (b .Dir , "src" , "DataFixtures" )); err == nil {
190
194
if err := executeCommand ([]string {"symfony" , "console" , "doctrine:fixtures:load" , "-n" }, b .Debug , false , nil ); err != nil {
191
- return err
195
+ return errors . WithStack ( err )
192
196
}
193
197
} else {
194
198
terminal .Println ("Skipped for this step" )
@@ -202,7 +206,7 @@ func (b *Book) Checkout(step string) error {
202
206
args = []string {"yarn" , "install" }
203
207
}
204
208
if err := executeCommand (args , b .Debug , false , nil ); err != nil {
205
- return err
209
+ return errors . WithStack ( err )
206
210
}
207
211
} else {
208
212
terminal .Println ("Skipped for this step" )
@@ -215,38 +219,38 @@ func (b *Book) Checkout(step string) error {
215
219
args = []string {"yarn" , "encore" , "dev" }
216
220
}
217
221
if err := executeCommand (args , b .Debug , false , nil ); err != nil {
218
- return err
222
+ return errors . WithStack ( err )
219
223
}
220
224
} else {
221
225
terminal .Println ("Skipped for this step" )
222
226
}
223
227
224
228
printBanner ("<comment>[WEB]</> Starting the Local Web Server" , b .Debug )
225
229
if err := executeCommand ([]string {"symfony" , "server:start" , "-d" }, b .Debug , false , nil ); err != nil {
226
- return err
230
+ return errors . WithStack ( err )
227
231
}
228
232
229
233
printBanner ("<comment>[WEB]</> Starting Message Consumer" , b .Debug )
230
234
if _ , err := os .Stat (filepath .Join (b .Dir , "src" , "MessageHandler" , "CommentMessageHandler.php" )); err == nil {
231
235
if err := executeCommand ([]string {"symfony" , "run" , "-d" , "--watch" , "config,src,templates,vendor" , "symfony" , "console" , "messenger:consume" , "async" , "-vv" }, b .Debug , false , nil ); err != nil {
232
- return err
236
+ return errors . WithStack ( err )
233
237
}
234
238
} else {
235
239
terminal .Println ("Skipped for this step" )
236
240
}
237
241
238
242
printBanner ("<comment>[SPA]</> Installing Node dependencies (might take some time)" , b .Debug )
239
243
if _ , err := os .Stat (filepath .Join (b .Dir , "spa" )); err == nil {
240
- os .Chdir (filepath .Join (b .Dir , "spa" ))
244
+ _ = os .Chdir (filepath .Join (b .Dir , "spa" ))
241
245
args := []string {"npm" , "install" }
242
246
if _ , err := os .Stat (filepath .Join (b .Dir , "yarn.lock" )); err == nil {
243
247
// old version of the book using Yarn instead of npm
244
248
args = []string {"yarn" , "install" }
245
249
}
246
250
if err := executeCommand (args , b .Debug , false , nil ); err != nil {
247
- return err
251
+ return errors . WithStack (err )
248
252
}
249
- os .Chdir (b .Dir )
253
+ _ = os .Chdir (b .Dir )
250
254
} else {
251
255
terminal .Println ("Skipped for this step" )
252
256
}
@@ -264,24 +268,24 @@ func (b *Book) Checkout(step string) error {
264
268
if endpoint .String () == "" {
265
269
return errors .Errorf ("unable to get the URL of the local web server:\n %s\n %s" , stderr .String (), endpoint .String ())
266
270
}
267
- os .Chdir (filepath .Join (b .Dir , "spa" ))
271
+ _ = os .Chdir (filepath .Join (b .Dir , "spa" ))
268
272
env := append (os .Environ (), "API_ENDPOINT=" + endpoint .String ())
269
273
args := []string {"npx" , "encore" , "dev" }
270
274
if _ , err := os .Stat (filepath .Join (b .Dir , "yarn.lock" )); err == nil {
271
275
args = []string {"yarn" , "encore" , "dev" }
272
276
}
273
277
if err := executeCommand (args , b .Debug , false , env ); err != nil {
274
- return err
278
+ return errors . WithStack ( err )
275
279
}
276
- os .Chdir (b .Dir )
280
+ _ = os .Chdir (b .Dir )
277
281
} else {
278
282
terminal .Println ("Skipped for this step" )
279
283
}
280
284
281
285
printBanner ("<comment>[SPA]</> Starting the Local Web Server" , b .Debug )
282
286
if _ , err := os .Stat (filepath .Join (b .Dir , "spa" )); err == nil {
283
287
if err := executeCommand ([]string {"symfony" , "server:start" , "-d" , "--passthru" , "index.html" , "--dir" , filepath .Join (b .Dir , "spa" )}, b .Debug , false , nil ); err != nil {
284
- return err
288
+ return errors . WithStack ( err )
285
289
}
286
290
} else {
287
291
terminal .Println ("Skipped for this step" )
@@ -322,7 +326,7 @@ func executeCommand(args []string, debug, skipErrors bool, env []string) error {
322
326
terminal .Println ("<error>[ KO ]</>" )
323
327
}
324
328
terminal .Print (buf .String ())
325
- return err
329
+ return errors . WithStack ( err )
326
330
}
327
331
if ! debug {
328
332
terminal .Println ("<info>[ OK ]</>" )
0 commit comments