diff --git a/server/core/config/valid/repo_cfg.go b/server/core/config/valid/repo_cfg.go index fb56d4b50f..e42e60158b 100644 --- a/server/core/config/valid/repo_cfg.go +++ b/server/core/config/valid/repo_cfg.go @@ -195,6 +195,10 @@ type CommandShell struct { ShellArgs []string } +func (s CommandShell) String() string { + return fmt.Sprintf("%s %s", s.Shell, strings.Join(s.ShellArgs, " ")) +} + type Step struct { StepName string ExtraArgs []string diff --git a/server/core/runtime/models/shell_command_runner.go b/server/core/runtime/models/shell_command_runner.go index ccdc99b1c2..7271f6789e 100644 --- a/server/core/runtime/models/shell_command_runner.go +++ b/server/core/runtime/models/shell_command_runner.go @@ -2,7 +2,6 @@ package models import ( "bufio" - "fmt" "io" "os/exec" "strings" @@ -112,10 +111,10 @@ func (s *ShellCommandRunner) RunCommandAsync(ctx command.ProjectContext) (chan<- stderr, _ := s.cmd.StderrPipe() stdin, _ := s.cmd.StdinPipe() - ctx.Log.Debug("starting %q in %q", s.command, s.workingDir) + ctx.Log.Debug("starting '%s %q' in '%s'", s.shell.String(), s.command, s.workingDir) err := s.cmd.Start() if err != nil { - err = errors.Wrapf(err, "running %q in %q", s.command, s.workingDir) + err = errors.Wrapf(err, "running '%s %q' in '%s'", s.shell.String(), s.command, s.workingDir) ctx.Log.Err(err.Error()) outCh <- Line{Err: err} return @@ -174,15 +173,13 @@ func (s *ShellCommandRunner) RunCommandAsync(ctx command.ProjectContext) (chan<- // We're done now. Send an error if there was one. if err != nil { - err = errors.Wrapf(err, "running %q in %q", - fmt.Sprintf("%s %s %q", s.shell.Shell, strings.Join(s.shell.ShellArgs, " "), s.command), - s.workingDir) + err = errors.Wrapf(err, "running '%s %q' in '%s'", + s.shell.String(), s.command, s.workingDir) log.Err(err.Error()) outCh <- Line{Err: err} } else { - log.Info("successfully ran %q in %q", - fmt.Sprintf("%s %s %q", s.shell.Shell, strings.Join(s.shell.ShellArgs, " "), s.command), - s.workingDir) + log.Info("successfully ran '%s %q' in '%s'", + s.shell.String(), s.command, s.workingDir) } }() diff --git a/server/core/terraform/terraform_client_internal_test.go b/server/core/terraform/terraform_client_internal_test.go index 40fe78842b..421e05c6ba 100644 --- a/server/core/terraform/terraform_client_internal_test.go +++ b/server/core/terraform/terraform_client_internal_test.go @@ -344,7 +344,7 @@ func TestDefaultClient_RunCommandAsync_ExitOne(t *testing.T) { _, outCh := client.RunCommandAsync(ctx, tmp, []string{"dying", "&&", "exit", "1"}, map[string]string{}, nil, "workspace") out, err := waitCh(outCh) - ErrEquals(t, fmt.Sprintf(`running "sh -c \"echo dying && exit 1\"" in %q: exit status 1`, tmp), err) + ErrEquals(t, fmt.Sprintf(`running 'sh -c \"echo dying && exit 1\"' in '%s': exit status 1`, tmp), err) // Test that we still get our output. Equals(t, "dying", out)