Skip to content

Commit

Permalink
review: cleanup log messages
Browse files Browse the repository at this point in the history
Signed-off-by: anryko <[email protected]>
  • Loading branch information
anryko committed Nov 3, 2024
1 parent a52d939 commit 3ef5951
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 4 additions & 0 deletions server/core/config/valid/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions server/core/runtime/models/shell_command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package models

import (
"bufio"
"fmt"
"io"
"os/exec"
"strings"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion server/core/terraform/terraform_client_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 3ef5951

Please sign in to comment.