mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-06 23:46:13 +02:00
Removed the wired error handling
This commit is contained in:
parent
0577d3b97f
commit
5d038dfd33
@ -4,6 +4,7 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
@ -19,8 +20,9 @@ import (
|
|||||||
// As return of output you need to give a string that will be written to stdin
|
// As return of output you need to give a string that will be written to stdin
|
||||||
// NOTE: If the return data is empty it won't written anything to stdin
|
// NOTE: If the return data is empty it won't written anything to stdin
|
||||||
// NOTE: You don't have to include a enter in the return data this function will do that for you
|
// NOTE: You don't have to include a enter in the return data this function will do that for you
|
||||||
func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) {
|
func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) error {
|
||||||
cmdOutput := []string{}
|
cmdOutput := []string{}
|
||||||
|
cmdOutputOffset := 0
|
||||||
|
|
||||||
splitCmd := str.ToArgv(command)
|
splitCmd := str.ToArgv(command)
|
||||||
cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
|
cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
|
||||||
@ -30,12 +32,8 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
|
|||||||
|
|
||||||
tty, err := pty.Start(cmd)
|
tty, err := pty.Start(cmd)
|
||||||
|
|
||||||
// go func() {
|
|
||||||
// _ = tty.Close()
|
|
||||||
// }()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var waitForBufio sync.WaitGroup
|
var waitForBufio sync.WaitGroup
|
||||||
@ -49,6 +47,8 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
|
|||||||
cmdOutput = append(cmdOutput, toOutput)
|
cmdOutput = append(cmdOutput, toOutput)
|
||||||
toWrite := output(toOutput)
|
toWrite := output(toOutput)
|
||||||
if len(toWrite) > 0 {
|
if len(toWrite) > 0 {
|
||||||
|
// don't do -1 because the next value is the username / password
|
||||||
|
cmdOutputOffset = len(cmdOutput)
|
||||||
_, _ = tty.Write([]byte(toWrite + "\n"))
|
_, _ = tty.Write([]byte(toWrite + "\n"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,10 +59,13 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
|
|||||||
tty.Close()
|
tty.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
waitForBufio.Wait()
|
waitForBufio.Wait()
|
||||||
return strings.Join(cmdOutput, " "), err
|
if len(cmdOutput) == cmdOutputOffset {
|
||||||
|
cmdOutputOffset--
|
||||||
|
}
|
||||||
|
return errors.New(err.Error() + ", " + strings.Join(cmdOutput[cmdOutputOffset:], " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorMessage, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanWordsWithNewLines is a copy of bufio.ScanWords but this also captures new lines
|
// scanWordsWithNewLines is a copy of bufio.ScanWords but this also captures new lines
|
||||||
|
@ -4,7 +4,6 @@ package commands
|
|||||||
|
|
||||||
// RunCommandWithOutputLiveWrapper runs a command live but because of windows compatibility this command can't be ran there
|
// RunCommandWithOutputLiveWrapper runs a command live but because of windows compatibility this command can't be ran there
|
||||||
// TODO: Remove this hack and replace it with a propper way to run commands live on windows
|
// TODO: Remove this hack and replace it with a propper way to run commands live on windows
|
||||||
func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) {
|
func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) error {
|
||||||
cmdOputput := c.RunCommand(command)
|
return c.RunCommand(command)
|
||||||
return cmdOputput.Error(), cmdOputput
|
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func (c *OSCommand) RunCommandWithOutput(command string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunCommandWithOutputLive runs RunCommandWithOutputLiveWrapper
|
// RunCommandWithOutputLive runs RunCommandWithOutputLiveWrapper
|
||||||
func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string) string) (errorMessage string, err error) {
|
func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string) string) error {
|
||||||
return RunCommandWithOutputLiveWrapper(c, command, output)
|
return RunCommandWithOutputLiveWrapper(c, command, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string)
|
|||||||
// The ask argument will be "username" or "password" and expects the user's password or username back
|
// The ask argument will be "username" or "password" and expects the user's password or username back
|
||||||
func (c *OSCommand) DetectUnamePass(command string, ask func(string) string) error {
|
func (c *OSCommand) DetectUnamePass(command string, ask func(string) string) error {
|
||||||
ttyText := ""
|
ttyText := ""
|
||||||
errMessage, err := c.RunCommandWithOutputLive(command, func(word string) string {
|
errMessage := c.RunCommandWithOutputLive(command, func(word string) string {
|
||||||
ttyText = ttyText + " " + word
|
ttyText = ttyText + " " + word
|
||||||
|
|
||||||
prompts := map[string]string{
|
prompts := map[string]string{
|
||||||
@ -85,13 +85,7 @@ func (c *OSCommand) DetectUnamePass(command string, ask func(string) string) err
|
|||||||
|
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
if err != nil {
|
return errMessage
|
||||||
if strings.Contains("exit status 128", err.Error()) {
|
|
||||||
errMessage = "exit status 128"
|
|
||||||
}
|
|
||||||
return errors.New(errMessage)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunCommand runs a command and just returns the error
|
// RunCommand runs a command and just returns the error
|
||||||
|
@ -320,7 +320,7 @@ func (gui *Gui) HandleCredentialsPopup(g *gocui.Gui, popupOpened bool, cmdErr er
|
|||||||
}
|
}
|
||||||
if cmdErr != nil {
|
if cmdErr != nil {
|
||||||
errMessage := cmdErr.Error()
|
errMessage := cmdErr.Error()
|
||||||
if errMessage == "exit status 128" {
|
if strings.Contains(errMessage, "exit status 128") {
|
||||||
errMessage = gui.Tr.SLocalize("PassUnameWrong")
|
errMessage = gui.Tr.SLocalize("PassUnameWrong")
|
||||||
}
|
}
|
||||||
_ = gui.createErrorPanel(g, errMessage)
|
_ = gui.createErrorPanel(g, errMessage)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user