Skip to content

Commit fb00ff4

Browse files
committed
fix: Removing Unit.AbsolutePath()
1 parent da3683b commit fb00ff4

5 files changed

Lines changed: 13 additions & 27 deletions

File tree

internal/component/unit.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/gruntwork-io/terragrunt/internal/tf"
1111
"github.com/gruntwork-io/terragrunt/internal/util"
1212
"github.com/gruntwork-io/terragrunt/pkg/config"
13-
"github.com/gruntwork-io/terragrunt/pkg/log"
1413
)
1514

1615
const (
@@ -258,19 +257,6 @@ func (u *Unit) String() string {
258257
)
259258
}
260259

261-
// AbsolutePath returns the absolute path of the unit.
262-
// If path conversion fails, logs the error and returns the original path.
263-
func (u *Unit) AbsolutePath(l log.Logger) string {
264-
absPath, err := filepath.Abs(u.path)
265-
if err != nil {
266-
l.Errorf("Error converting unit path %s to absolute path: %v", u.path, err)
267-
268-
return u.path
269-
}
270-
271-
return absPath
272-
}
273-
274260
// DisplayPath returns the path relative to DiscoveryContext.WorkingDir for display purposes.
275261
// Falls back to the original path if relative path calculation fails or WorkingDir is empty.
276262
func (u *Unit) DisplayPath() string {

internal/component/unit_output.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"io"
66
"sync"
7-
8-
"github.com/gruntwork-io/terragrunt/pkg/log"
97
)
108

119
// flusher is any writer that supports Flush() error.
@@ -40,7 +38,7 @@ func unitOutputLock(key string) *sync.Mutex {
4038

4139
// FlushOutput flushes buffer data to the given writer for this unit, if the writer supports it.
4240
// This is safe to call even if u or w is nil.
43-
func FlushOutput(l log.Logger, u *Unit, w io.Writer) error {
41+
func FlushOutput(u *Unit, w io.Writer) error {
4442
if u == nil || w == nil {
4543
return nil
4644
}
@@ -52,7 +50,7 @@ func FlushOutput(l log.Logger, u *Unit, w io.Writer) error {
5250

5351
// Use parent writer's address as lock key to serialize flushes to same parent.
5452
// Falls back to unit path for writers without parentWriterProvider.
55-
key := u.AbsolutePath(l)
53+
key := u.Path()
5654
if pwp, ok := w.(parentWriterProvider); ok {
5755
key = fmt.Sprintf("%p", pwp.ParentWriter())
5856
}

internal/runner/common/unit_runner.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ func (runner *UnitRunner) runTerragrunt(
5454

5555
defer func() {
5656
// Flush buffered output for this unit, if the writer supports it.
57-
if err := component.FlushOutput(l, runner.Unit, opts.Writer); err != nil {
57+
if err := component.FlushOutput(runner.Unit, opts.Writer); err != nil {
5858
l.Errorf("Error flushing output for unit %s: %v", runner.Unit.Path(), err)
5959
}
6060
}()
6161

6262
// Only create report entries if report is not nil
6363
if r != nil {
64-
unitPath := runner.Unit.AbsolutePath(l)
64+
unitPath := runner.Unit.Path()
6565
unitPath = util.CleanPath(unitPath)
6666

6767
// Pass the discovery context fields for worktree scenarios
@@ -93,14 +93,14 @@ func (runner *UnitRunner) runTerragrunt(
9393

9494
// Store the unit exit code in the global map using the unit path as key.
9595
if globalExitCode != nil {
96-
unitPath := filepath.Dir(opts.OriginalTerragruntConfigPath)
96+
unitPath := runner.Unit.Path()
9797
code := unitExitCode.Get(unitPath)
9898
globalExitCode.Set(unitPath, code)
9999
}
100100

101101
// End the run with appropriate result (only if report is not nil)
102102
if r != nil {
103-
unitPath := runner.Unit.AbsolutePath(l)
103+
unitPath := runner.Unit.Path()
104104
unitPath = util.CleanPath(unitPath)
105105

106106
if runErr != nil {

internal/runner/runnerpool/runner.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ func (rnr *Runner) Run(ctx context.Context, l log.Logger, stackOpts *options.Ter
364364
if r != nil {
365365
for _, u := range rnr.Stack.Units {
366366
if u.Excluded() {
367-
// Ensure path is absolute for reporting
368-
unitPath := u.AbsolutePath(l)
367+
unitPath := u.Path()
369368

370369
// Pass the discovery context fields for worktree scenarios
371370
var ensureOpts []report.EndOption
@@ -506,8 +505,7 @@ func (rnr *Runner) Run(ctx context.Context, l log.Logger, stackOpts *options.Ter
506505
continue
507506
}
508507

509-
// Ensure path is absolute for reporting
510-
unitPath := unit.AbsolutePath(l)
508+
unitPath := unit.Path()
511509

512510
// Pass the discovery context fields for worktree scenarios
513511
var ensureOpts []report.EndOption

test/integration_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,11 @@ func TestDetailedExitCodeChangesPresentAllWithSource(t *testing.T) {
428428
ctx := t.Context()
429429
ctx = tf.ContextWithDetailedExitCode(ctx, exitCode)
430430

431-
_, _, err := helpers.RunTerragruntCommandWithOutputWithContext(t, ctx, "terragrunt run --all --non-interactive --working-dir "+rootPath+" -- plan -detailed-exitcode")
431+
_, _, err := helpers.RunTerragruntCommandWithOutputWithContext(
432+
t,
433+
ctx,
434+
"terragrunt run --all --non-interactive --working-dir "+rootPath+" -- plan -detailed-exitcode",
435+
)
432436
require.NoError(t, err)
433437
assert.Equal(t, 2, exitCode.GetFinalDetailedExitCode())
434438
}

0 commit comments

Comments
 (0)