diff --git a/error.go b/error.go index 82b96d9..611bd65 100644 --- a/error.go +++ b/error.go @@ -8,13 +8,22 @@ import ( ) var ( - errorHeader = lipgloss.NewStyle().Foreground(lipgloss.Color("#F1F1F1")).Background(lipgloss.Color("#FF5F87")).Bold(true).Padding(0, 1).Margin(1).MarginLeft(2).SetString("ERROR") - errorDetails = lipgloss.NewStyle().Foreground(lipgloss.Color("#757575")).Margin(0, 0, 1, 2) + errorHeader = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#F1F1F1")). + Background(lipgloss.Color("#FF5F87")). + Bold(true). + Padding(0, 1). + Margin(1). + MarginLeft(2). + SetString("ERROR") + errorDetails = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#757575")). + MarginLeft(2) ) func printError(title string, err error) { - fmt.Printf("%s\n", lipgloss.JoinHorizontal(lipgloss.Center, errorHeader.String(), title)) - fmt.Printf("%s\n", errorDetails.Render(err.Error())) + fmt.Println(lipgloss.JoinHorizontal(lipgloss.Center, errorHeader.String(), title)) + fmt.Println(errorDetails.Render(err.Error())) } func printErrorFatal(title string, err error) { diff --git a/main.go b/main.go index 5a710d7..3a0919d 100644 --- a/main.go +++ b/main.go @@ -85,6 +85,9 @@ func main() { if config.Execute != "" { input, err = executeCommand(config) if err != nil { + if input != "" { + err = fmt.Errorf("%w\n%s", err, input) + } printErrorFatal("Something went wrong", err) } if input == "" { diff --git a/pty.go b/pty.go index 42fd0fd..27e7f7c 100644 --- a/pty.go +++ b/pty.go @@ -42,13 +42,15 @@ func executeCommand(config Config) (string, error) { } defer pty.Close() //nolint: errcheck var out bytes.Buffer + var errorOut bytes.Buffer go func() { _, _ = io.Copy(&out, pty) + errorOut.Write(out.Bytes()) }() err = cmd.Wait() if err != nil { - return "", err //nolint: wrapcheck + return errorOut.String(), err //nolint: wrapcheck } return out.String(), nil }