88 "slices"
99 "sync"
1010 "time"
11+
12+ "github.com/gruntwork-io/terragrunt/pkg/log"
1113)
1214
1315// Report captures data for a report/summary.
@@ -129,7 +131,7 @@ var ErrRunAlreadyExists = errors.New("run already exists")
129131
130132// AddRun adds a run to the report.
131133// If the run already exists, it returns the ErrRunAlreadyExists error.
132- func (r * Report ) AddRun (run * Run ) error {
134+ func (r * Report ) AddRun (l log. Logger , run * Run ) error {
133135 r .mu .Lock ()
134136 defer r .mu .Unlock ()
135137
@@ -139,6 +141,8 @@ func (r *Report) AddRun(run *Run) error {
139141 }
140142 }
141143
144+ l .Debugf ("Adding report run %s" , run .Path )
145+
142146 r .Runs = append (r .Runs , run )
143147
144148 return nil
@@ -169,22 +173,26 @@ func (r *Report) GetRun(path string) (*Run, error) {
169173// EnsureRun tries to get a run from the report.
170174// If the run does not exist, it creates a new run and adds it to the report, then returns the run.
171175// This is useful when a run is being ended that might not have been started due to exclusion, etc.
172- func (r * Report ) EnsureRun (path string ) (* Run , error ) {
176+ func (r * Report ) EnsureRun (l log. Logger , path string ) (* Run , error ) {
173177 run , err := r .GetRun (path )
174178 if err == nil {
179+ l .Debugf ("Report run %s already exists, returning existing run" , path )
180+
175181 return run , nil
176182 }
177183
178184 if ! errors .Is (err , ErrRunNotFound ) {
179185 return run , err
180186 }
181187
188+ l .Debugf ("Report run %s not found, creating new run" , path )
189+
182190 run , err = NewRun (path )
183191 if err != nil {
184192 return run , err
185193 }
186194
187- if err = r .AddRun (run ); err != nil {
195+ if err = r .AddRun (l , run ); err != nil {
188196 return run , err
189197 }
190198
@@ -195,7 +203,7 @@ func (r *Report) EnsureRun(path string) (*Run, error) {
195203// If the run does not exist, it returns the ErrRunNotFound error.
196204// By default, the run is assumed to have succeeded. To change this, pass WithResult to the function.
197205// If the run has already ended from an early exit, it does nothing.
198- func (r * Report ) EndRun (path string , endOptions ... EndOption ) error {
206+ func (r * Report ) EndRun (l log. Logger , path string , endOptions ... EndOption ) error {
199207 r .mu .Lock ()
200208 defer r .mu .Unlock ()
201209
@@ -231,6 +239,8 @@ func (r *Report) EndRun(path string, endOptions ...EndOption) error {
231239 endOption (run )
232240 }
233241
242+ l .Debugf ("Ending report run %s with result %s" , path , run .Result )
243+
234244 return nil
235245}
236246
0 commit comments