Skip to content

Commit cc66558

Browse files
authored
Make sure plan failures post comment (#2114)
* add more error reporting to the comments
1 parent 74af869 commit cc66558

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

libs/execution/execution.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package execution
22

33
import (
44
"fmt"
5+
"github.com/diggerhq/digger/libs/iac_utils"
6+
"github.com/diggerhq/digger/libs/locking"
7+
"github.com/diggerhq/digger/libs/scheduler"
8+
"github.com/diggerhq/digger/libs/storage"
9+
"github.com/samber/lo"
510
"log/slog"
611
"os"
712
"path"
@@ -10,12 +15,6 @@ import (
1015
"strconv"
1116
"strings"
1217

13-
"github.com/diggerhq/digger/libs/iac_utils"
14-
"github.com/diggerhq/digger/libs/locking"
15-
"github.com/diggerhq/digger/libs/scheduler"
16-
"github.com/diggerhq/digger/libs/storage"
17-
"github.com/samber/lo"
18-
1918
"github.com/diggerhq/digger/libs/comment_utils/reporting"
2019
configuration "github.com/diggerhq/digger/libs/digger_config"
2120
)
@@ -247,11 +246,13 @@ func (d DiggerExecutor) Plan() (*iac_utils.IacSummary, bool, bool, string, strin
247246
var stdout, stderr string
248247
isEmptyPlan, stdout, stderr, err = d.TerraformExecutor.Plan(planArgs, d.CommandEnvVars, d.PlanPathProvider.LocalPlanFilePath(), d.PlanStage.FilterRegex)
249248
if err != nil {
249+
reportTerraformError(d.Reporter, stderr)
250250
return nil, false, false, "", "", fmt.Errorf("error executing plan: %v, stdout: %v, stderr: %v", err, stdout, stderr)
251251
}
252252

253253
plan, terraformPlanOutputJsonString, planSummary, isEmptyPlan, err = d.postProcessPlan(stdout)
254254
if err != nil {
255+
reportError(d.Reporter, err.Error())
255256
slog.Debug("error post processing plan",
256257
"error", err,
257258
"plan", plan,
@@ -275,6 +276,7 @@ func (d DiggerExecutor) Plan() (*iac_utils.IacSummary, bool, bool, string, strin
275276
d.RunEnvVars["DIGGER_PLANFILE"] = d.PlanPathProvider.LocalPlanFilePath()
276277
_, _, err := d.CommandRunner.Run(d.ProjectPath, step.Shell, commands, d.RunEnvVars)
277278
if err != nil {
279+
reportError(d.Reporter, err.Error())
278280
return nil, false, false, "", "", fmt.Errorf("error running command: %v", err)
279281
}
280282
}
@@ -283,10 +285,12 @@ func (d DiggerExecutor) Plan() (*iac_utils.IacSummary, bool, bool, string, strin
283285
if !hasPlanStep {
284286
rawPlan, _, err := d.TerraformExecutor.Show(make([]string, 0), d.CommandEnvVars, d.PlanPathProvider.LocalPlanFilePath(), false)
285287
if err != nil {
288+
reportTerraformError(d.Reporter, err.Error())
286289
return nil, false, false, "", "", fmt.Errorf("error running terraform show: %v", err)
287290
}
288291
plan, terraformPlanOutputJsonString, planSummary, isEmptyPlan, err = d.postProcessPlan(rawPlan)
289292
if err != nil {
293+
reportError(d.Reporter, err.Error())
290294
slog.Debug("error post processing plan",
291295
"error", err,
292296
"plan", plan,

0 commit comments

Comments
 (0)