Skip to content

Commit

Permalink
Merge pull request #1854 from manuelbuil/fixPowershell
Browse files Browse the repository at this point in the history
Improve the log from powershell
  • Loading branch information
manuelbuil authored Jan 12, 2024
2 parents e8fb810 + 07ad900 commit c25af46
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/powershell/powershell.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strings"
)

//commandWrapper ensures that exceptions are written to stdout and the powershell process exit code is -1
// commandWrapper ensures that exceptions are written to stdout and the powershell process exit code is -1
const commandWrapper = `$ErrorActionPreference="Stop";try { %s } catch { Write-Host $_; os.Exit(-1) }`

// RunCommand executes a given powershell command.
Expand All @@ -37,7 +37,7 @@ func RunCommand(command string) ([]byte, error) {
stdout, err := cmd.Output()
if err != nil {
if cmd.ProcessState.ExitCode() != 0 {
message := strings.TrimSpace(string(stdout))
message := fmt.Sprintf("error: %v while running the command: %v.", err, cmd) + " Command output: " + strings.TrimSpace(string(stdout))
return []byte{}, errors.New(message)
}

Expand Down Expand Up @@ -66,12 +66,12 @@ func RunCommandWithJsonResult(command string, v interface{}) error {

stdout, err := RunCommandf(wrappedCommand)
if err != nil {
return err
return fmt.Errorf("error while executing command: %w", err)
}

err = json.Unmarshal(stdout, v)
if err != nil {
return err
return fmt.Errorf("error while unmarshalling stdout: %w", err)
}

return nil
Expand Down

0 comments on commit c25af46

Please sign in to comment.