@@ -2330,17 +2330,30 @@ func (fs *FileSystem) runPlan(currentRunDir string, currentRunConfigPaths []stri
2330
2330
return err
2331
2331
}
2332
2332
defer db .Close ()
2333
- err = db .Update (func (t * bolt.Tx ) error {
2333
+ err = db .Update (func (t * bolt.Tx ) ( errFinal error ) {
2334
2334
logrus .Trace ("planning finished. Update start" )
2335
2335
defer logrus .Trace ("planning finished. Update end" )
2336
2336
// checks
2337
2337
logrus .Debug ("planning finished. inside Update. just before checks start" )
2338
2338
project , err := fs .readProject (t , workspaceId , projectId )
2339
2339
if err != nil {
2340
- logrus .Errorf ("inside runPlan, failed to read the project after planning completed. Error: %q " , err )
2341
- return err
2340
+ errFinal = fmt .Errorf ("inside runPlan, failed to read the project after planning completed. Error: %w " , err )
2341
+ return errFinal
2342
2342
}
2343
2343
// update state
2344
+ defer func () {
2345
+ logrus .Debug ("planning finished. inside deferred Update. just before update start in defer" )
2346
+ logrus .Debugf ("deferred Update project %+v" , project )
2347
+ if errFinal != nil {
2348
+ logrus .Debugf ("deferred Update project already an error: %q" , errFinal )
2349
+ return
2350
+ }
2351
+ if err := fs .updateProject (t , workspaceId , project ); err != nil {
2352
+ logrus .Debugf ("deferred Update project error: %+v" , err )
2353
+ errFinal = fmt .Errorf ("failed to update the project to unlock the plan generation. Error: %w" , err )
2354
+ }
2355
+ logrus .Debug ("planning finished. inside deferred Update near end" )
2356
+ }()
2344
2357
logrus .Debug ("planning finished. inside Update. just before update start" )
2345
2358
if strings .HasPrefix (currentRunSrcDir , "git+" ) {
2346
2359
project .Status [types .ProjectStatusRemoteInputSources ] = true
@@ -2362,21 +2375,30 @@ func (fs *FileSystem) runPlan(currentRunDir string, currentRunConfigPaths []stri
2362
2375
logrus .Errorf ("planning for project %s stopped because the context was closed. Error: %q" , projectId , err )
2363
2376
}
2364
2377
}
2365
- if err := fs .updateProject (t , workspaceId , project ); err != nil {
2366
- return fmt .Errorf ("failed to update the project to unlock the plan generation. Error: %q" , err )
2367
- }
2368
2378
// effects
2369
2379
logrus .Debug ("planning finished. inside Update. just before effects start" )
2370
2380
projInputsDir := filepath .Join (common .Config .DataDir , PROJECTS_DIR , projectId , INPUTS_DIR , EXPANDED_DIR )
2371
2381
dstPlanPath := filepath .Join (projInputsDir , M2K_PLAN_FILENAME )
2372
2382
srcPlanPath := filepath .Join (currentRunOutDir , M2K_PLAN_FILENAME )
2383
+ if err := cmd .Wait (); err != nil {
2384
+ project .Status [types .ProjectStatusPlan ] = false
2385
+ project .Status [types .ProjectStatusPlanError ] = true
2386
+ logrus .Errorf ("failed to finish planning using move2kube. Error: %q" , err )
2387
+ return errFinal
2388
+ }
2373
2389
if err := os .MkdirAll (projInputsDir , DEFAULT_DIRECTORY_PERMISSIONS ); err != nil {
2374
- return fmt .Errorf ("failed to create the project inputs expanded directory at path %s to copy the plan to. Error: %q" , projInputsDir , err )
2390
+ project .Status [types .ProjectStatusPlan ] = false
2391
+ project .Status [types .ProjectStatusPlanError ] = true
2392
+ logrus .Errorf ("failed to create the project inputs expanded directory at path %s to copy the plan to. Error: %q" , projInputsDir , err )
2393
+ return errFinal
2375
2394
}
2376
2395
if err := CopyFile (dstPlanPath , srcPlanPath ); err != nil {
2377
- return fmt .Errorf ("failed to copy the plan file from %s to %s after planning finished. Error: %q" , srcPlanPath , dstPlanPath , err )
2396
+ project .Status [types .ProjectStatusPlan ] = false
2397
+ project .Status [types .ProjectStatusPlanError ] = true
2398
+ logrus .Errorf ("failed to copy the plan file from %s to %s after planning finished. Error: %q" , srcPlanPath , dstPlanPath , err )
2399
+ return errFinal
2378
2400
}
2379
- return nil
2401
+ return errFinal
2380
2402
})
2381
2403
if err != nil {
2382
2404
logrus .Errorf ("failed to update the database after planning finished. Error: %q" , err )
0 commit comments