Skip to content

Commit

Permalink
feat(#118): improve error message for --execute (#119)
Browse files Browse the repository at this point in the history
* feat(#118): improve error message for `--execute`

* fix: use previous styles

* docs: add comment to clarify change

* fix: print full error message

* feat: change to error format

Co-authored-by: ccoVeille <[email protected]>

* refactor: `input` as `out` to match `executeCommand`

Also prints new line after error status.

* feat: use `Println`

Co-authored-by: ccoVeille <[email protected]>

* refactor: include entire error msg

* fix: input must be set in --execute

---------

Co-authored-by: bashbunni <[email protected]>
Co-authored-by: ccoVeille <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2024
1 parent bcb36b7 commit 425055f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
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")).
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) {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
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.Write(out.Bytes())
}()

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

Check failure on line 53 in pty.go

View workflow job for this annotation

GitHub Actions / lint-soft

directive `//nolint: wrapcheck` is unused for linter "wrapcheck" (nolintlint)
}
return out.String(), nil
}

0 comments on commit 425055f

Please sign in to comment.