Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve error msg #139

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")).
Margin(0, 0, 1, 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) {
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func main() {
if config.Execute != "" {
input, err = executeCommand(config)
if err != nil {
if input != "" {
// show the full error message output
printErrorFatal("Something went wrong", errors.New(input))
}
printErrorFatal("Something went wrong", err)
}
if input == "" {
Expand Down
4 changes: 3 additions & 1 deletion pty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.WriteString(out.String())
}()

err = cmd.Wait()
if err != nil {
return "", err //nolint: wrapcheck
return errorOut.String(), err
}
return out.String(), nil
}
Loading