Skip to content

Commit 425055f

Browse files
AlejandroSuerobashbunniccoVeille
authored
feat(#118): improve error message for --execute (#119)
* 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]>
1 parent bcb36b7 commit 425055f

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

error.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ import (
88
)
99

1010
var (
11-
errorHeader = lipgloss.NewStyle().Foreground(lipgloss.Color("#F1F1F1")).Background(lipgloss.Color("#FF5F87")).Bold(true).Padding(0, 1).Margin(1).MarginLeft(2).SetString("ERROR")
12-
errorDetails = lipgloss.NewStyle().Foreground(lipgloss.Color("#757575")).Margin(0, 0, 1, 2)
11+
errorHeader = lipgloss.NewStyle().
12+
Foreground(lipgloss.Color("#F1F1F1")).
13+
Background(lipgloss.Color("#FF5F87")).
14+
Bold(true).
15+
Padding(0, 1).
16+
Margin(1).
17+
MarginLeft(2).
18+
SetString("ERROR")
19+
errorDetails = lipgloss.NewStyle().
20+
Foreground(lipgloss.Color("#757575")).
21+
MarginLeft(2)
1322
)
1423

1524
func printError(title string, err error) {
16-
fmt.Printf("%s\n", lipgloss.JoinHorizontal(lipgloss.Center, errorHeader.String(), title))
17-
fmt.Printf("%s\n", errorDetails.Render(err.Error()))
25+
fmt.Println(lipgloss.JoinHorizontal(lipgloss.Center, errorHeader.String(), title))
26+
fmt.Println(errorDetails.Render(err.Error()))
1827
}
1928

2029
func printErrorFatal(title string, err error) {

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func main() {
8585
if config.Execute != "" {
8686
input, err = executeCommand(config)
8787
if err != nil {
88+
if input != "" {
89+
err = fmt.Errorf("%w\n%s", err, input)
90+
}
8891
printErrorFatal("Something went wrong", err)
8992
}
9093
if input == "" {

pty.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ func executeCommand(config Config) (string, error) {
4242
}
4343
defer pty.Close() //nolint: errcheck
4444
var out bytes.Buffer
45+
var errorOut bytes.Buffer
4546
go func() {
4647
_, _ = io.Copy(&out, pty)
48+
errorOut.Write(out.Bytes())
4749
}()
4850

4951
err = cmd.Wait()
5052
if err != nil {
51-
return "", err //nolint: wrapcheck
53+
return errorOut.String(), err //nolint: wrapcheck
5254
}
5355
return out.String(), nil
5456
}

0 commit comments

Comments
 (0)