Skip to content

Commit

Permalink
fix: error message with stdout/stderr in the case of sharing command …
Browse files Browse the repository at this point in the history
…fails (#1984)

## What this PR does / why we need it:

Improve the error message by including the stdout and stderr of failed
Outputs Sharing command.

## Which issue(s) this PR fixes:
Fixes #1975

## Special notes for your reviewer:

## Does this PR introduce a user-facing change?
```
yes, fixes an issue
```
  • Loading branch information
i4ki authored Nov 29, 2024
2 parents 5139635 + 31745d2 commit d69c277
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Given a version number `MAJOR.MINOR.PATCH`, we increment the:

- Fix the command-line parsing of `run` and `script run` which were not failing from unknown flags.
- Fix `create --all-terragrunt` creating Terragrunt stacks with cycles.
- Panic in the Terragrunt integration when the project had modules with dependency paths outside the current Terramate project.
- Now Terramate throw a warning for such configurations.
- Improve the error reporting of the Outputs Sharing feature.
- Fix crash in the Terragrunt integration when the project had modules with dependency paths outside the current Terramate project.
- A warning will be shown for such configurations.

## v0.11.3

Expand Down
7 changes: 5 additions & 2 deletions cmd/terramate/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func (c *cli) runAll(
err := cmd.Run()
if err != nil {
if !task.MockOnFail {
errs.Append(errors.E(err, "failed to execute: %s (stderr: %s)", cmd.String(), stderr.Bytes()))
errs.Append(errors.E(err, "failed to execute: (cmd: %s) (stdout: %s) (stderr: %s)", cmd.String(), stdout.String(), stderr.String()))
c.cloudSyncAfter(cloudRun, runResult{ExitCode: -1}, errors.E(ErrRunCommandNotExecuted, err))
releaseResource()
failedTaskIndex = taskIndex
Expand All @@ -502,7 +502,10 @@ func (c *cli) runAll(
break tasksLoop
}

printer.Stderr.Warnf("failed to execute `sharing_backend` command: %v", err)
printer.Stderr.WarnWithDetails(
"failed to execute `sharing_backend` command",
errors.E(err, "(cmd: %s) (stdout: %s) (stderr: %s)", cmd.String(), stdout.String(), stderr.String()),
)
} else {
stdoutBytes := stdout.Bytes()
typ, err := json.ImpliedType(stdoutBytes)
Expand Down
6 changes: 3 additions & 3 deletions e2etests/core/run_parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,23 @@ func TestParallelSharingOutputFailure(t *testing.T) {
RunExpected{
Status: 1,
IgnoreStdout: true,
StderrRegex: regexp.QuoteMeta("failed to execute: does_not_exist"),
StderrRegex: regexp.QuoteMeta("failed to execute: (cmd: does_not_exist)"),
},
)
AssertRunResult(t,
tmcli.Run("run", "--enable-sharing", "--continue-on-error", "--parallel=2", "--quiet", "--", HelperPath, "echo", "okay"),
RunExpected{
Status: 1,
IgnoreStdout: true,
StderrRegex: regexp.QuoteMeta("failed to execute: does_not_exist"),
StderrRegex: regexp.QuoteMeta("failed to execute: (cmd: does_not_exist)"),
},
)
AssertRunResult(t,
tmcli.Run("run", "--dry-run", "--enable-sharing", "--continue-on-error", "--parallel=2", "--quiet", "--", HelperPath, "echo", "okay"),
RunExpected{
Status: 1,
IgnoreStdout: true,
StderrRegex: regexp.QuoteMeta("failed to execute: does_not_exist"),
StderrRegex: regexp.QuoteMeta("failed to execute: (cmd: does_not_exist)"),
},
)
}
Expand Down
5 changes: 4 additions & 1 deletion e2etests/core/run_sharing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ func TestRunSharing(t *testing.T) {
"local_file.s3_file",
},
NoStdoutRegex: "local_file.s2_file",
StderrRegex: regexp.QuoteMeta("Warning: failed to execute `sharing_backend` command: exit status 1"),
StderrRegexes: []string{
regexp.QuoteMeta("Warning: failed to execute `sharing_backend`"),
regexp.QuoteMeta("helper exit 1) (stdout: ) (stderr: ): exit status 1"),
},
})
},
},
Expand Down

0 comments on commit d69c277

Please sign in to comment.