Skip to content

Commit

Permalink
fix: print full error message
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroSuero committed Sep 8, 2024
1 parent a315561 commit d340702
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 7 additions & 5 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 1 addition & 7 deletions pty.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io"
"os"
"os/exec"
"strings"
"syscall"

"github.com/caarlos0/go-shellwords"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d340702

Please sign in to comment.