From d340702ffb0ba8f6db82877a321f164e58e0932f Mon Sep 17 00:00:00 2001 From: AlejandroSuero Date: Sun, 8 Sep 2024 13:10:33 +0200 Subject: [PATCH] fix: print full error message --- error.go | 12 +++++++----- pty.go | 8 +------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/error.go b/error.go index 82b96d9..8796ef0 100644 --- a/error.go +++ b/error.go @@ -3,18 +3,20 @@ package main import ( "fmt" "os" + "strings" "github.com/charmbracelet/lipgloss" ) -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) -) +var errorHeader = lipgloss.NewStyle().Foreground(lipgloss.Color("#F1F1F1")).Background(lipgloss.Color("#FF5F87")).Bold(true).Padding(0, 1).Margin(1).MarginLeft(2).SetString("ERROR") +var 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())) + splittedError := strings.Split(err.Error(), "\n") + for _, line := range splittedError { + fmt.Printf("%s\n", errorDetails.Render(line)) + } } func printErrorFatal(title string, err error) { diff --git a/pty.go b/pty.go index ab6dd55..27e7f7c 100644 --- a/pty.go +++ b/pty.go @@ -9,7 +9,6 @@ import ( "io" "os" "os/exec" - "strings" "syscall" "github.com/caarlos0/go-shellwords" @@ -46,12 +45,7 @@ func executeCommand(config Config) (string, error) { var errorOut bytes.Buffer go func() { _, _ = io.Copy(&out, pty) - splittedOut := strings.Split(out.String(), "\n") - if len(splittedOut) > 0 { - errorOut.WriteString(splittedOut[0]) - } else { - errorOut.WriteString(out.String()) - } + errorOut.Write(out.Bytes()) }() err = cmd.Wait()