Skip to content

Commit

Permalink
format error with more verbosity (#180)
Browse files Browse the repository at this point in the history
follow up to #179
  • Loading branch information
joshrwolf authored Aug 29, 2024
1 parent 888272e commit 3b803f1
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion internal/harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"strings"
"sync"
)

Expand Down Expand Up @@ -35,7 +36,32 @@ type RunError struct {
}

func (e *RunError) Error() string {
return fmt.Sprintf("%s\n%s\nexit status %d", e.Cmd, e.CombinedOutput, e.ExitCode)
var sb strings.Builder

sb.WriteString(fmt.Sprintf("Error executing command (exit code %d)\n\n", e.ExitCode))

sb.WriteString("Command:\n")

cmdLines := strings.Split(strings.TrimSpace(e.Cmd), "\n")
for _, line := range cmdLines {
sb.WriteString("\t")
sb.WriteString(strings.TrimLeft(line, " \t"))
sb.WriteString("\n")
}

// Add a newline between command and output
sb.WriteString("\n")

// Write the output
sb.WriteString("Output (stdout/stderr):\n")
outputLines := strings.Split(strings.TrimSpace(e.CombinedOutput), "\n")
for _, line := range outputLines {
sb.WriteString("\t")
sb.WriteString(strings.TrimLeft(line, " \t"))
sb.WriteString("\n")
}

return sb.String()
}

func DefaultCmd() []string {
Expand Down

0 comments on commit 3b803f1

Please sign in to comment.