Skip to content

Commit e4b2993

Browse files
fix: check the exit code
Signed-off-by: Harikrishnan Balagopal <[email protected]>
1 parent 273206c commit e4b2993

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

internal/filesystem/filesystem.go

+31-9
Original file line numberDiff line numberDiff line change
@@ -2330,17 +2330,30 @@ func (fs *FileSystem) runPlan(currentRunDir string, currentRunConfigPaths []stri
23302330
return err
23312331
}
23322332
defer db.Close()
2333-
err = db.Update(func(t *bolt.Tx) error {
2333+
err = db.Update(func(t *bolt.Tx) (errFinal error) {
23342334
logrus.Trace("planning finished. Update start")
23352335
defer logrus.Trace("planning finished. Update end")
23362336
// checks
23372337
logrus.Debug("planning finished. inside Update. just before checks start")
23382338
project, err := fs.readProject(t, workspaceId, projectId)
23392339
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
23422342
}
23432343
// 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+
}()
23442357
logrus.Debug("planning finished. inside Update. just before update start")
23452358
if strings.HasPrefix(currentRunSrcDir, "git+") {
23462359
project.Status[types.ProjectStatusRemoteInputSources] = true
@@ -2362,21 +2375,30 @@ func (fs *FileSystem) runPlan(currentRunDir string, currentRunConfigPaths []stri
23622375
logrus.Errorf("planning for project %s stopped because the context was closed. Error: %q", projectId, err)
23632376
}
23642377
}
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-
}
23682378
// effects
23692379
logrus.Debug("planning finished. inside Update. just before effects start")
23702380
projInputsDir := filepath.Join(common.Config.DataDir, PROJECTS_DIR, projectId, INPUTS_DIR, EXPANDED_DIR)
23712381
dstPlanPath := filepath.Join(projInputsDir, M2K_PLAN_FILENAME)
23722382
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+
}
23732389
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
23752394
}
23762395
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
23782400
}
2379-
return nil
2401+
return errFinal
23802402
})
23812403
if err != nil {
23822404
logrus.Errorf("failed to update the database after planning finished. Error: %q", err)

0 commit comments

Comments
 (0)