1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

use go-errors package to display stacktrace of errors that cause panics

This commit is contained in:
Jesse Duffield
2019-02-11 21:30:27 +11:00
parent 3a607061a2
commit cfe3605e6b
13 changed files with 55 additions and 37 deletions

View File

@ -5,7 +5,7 @@ package commands
import (
"bufio"
"bytes"
"errors"
"github.com/go-errors/errors"
"os"
"os/exec"
"strings"

View File

@ -1,12 +1,13 @@
package commands
import (
"errors"
"fmt"
"os"
"os/exec"
"strings"
"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sirupsen/logrus"
@ -27,11 +28,11 @@ func navigateToRepoRootDirectory(stat func(string) (os.FileInfo, error), chdir f
}
if !os.IsNotExist(err) {
return err
return errors.Wrap(err, 0)
}
if err = chdir(".."); err != nil {
return err
return errors.Wrap(err, 0)
}
}
}

View File

@ -1,13 +1,14 @@
package commands
import (
"errors"
"io/ioutil"
"os"
"os/exec"
"regexp"
"strings"
"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/mgutz/str"
@ -122,7 +123,7 @@ func sanitisedCommandOutput(output []byte, err error) (string, error) {
// errors like 'exit status 1' are not very useful so we'll create an error
// from the combined output
if outputString == "" {
return "", err
return "", errors.Wrap(err, 0)
}
return outputString, errors.New(outputString)
}
@ -201,12 +202,12 @@ func (c *OSCommand) Unquote(message string) string {
func (c *OSCommand) AppendLineToFile(filename, line string) error {
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
return err
return errors.Wrap(err, 0)
}
defer f.Close()
_, err = f.WriteString("\n" + line)
return err
return errors.Wrap(err, 0)
}
// CreateTempFile writes a string to a new temp file and returns the file's name
@ -214,16 +215,16 @@ func (c *OSCommand) CreateTempFile(filename, content string) (string, error) {
tmpfile, err := ioutil.TempFile("", filename)
if err != nil {
c.Log.Error(err)
return "", err
return "", errors.Wrap(err, 0)
}
if _, err := tmpfile.WriteString(content); err != nil {
c.Log.Error(err)
return "", err
return "", errors.Wrap(err, 0)
}
if err := tmpfile.Close(); err != nil {
c.Log.Error(err)
return "", err
return "", errors.Wrap(err, 0)
}
return tmpfile.Name(), nil
@ -231,5 +232,6 @@ func (c *OSCommand) CreateTempFile(filename, content string) (string, error) {
// RemoveFile removes a file at the specified path
func (c *OSCommand) RemoveFile(filename string) error {
return os.Remove(filename)
err := os.Remove(filename)
return errors.Wrap(err, 0)
}

View File

@ -1,9 +1,10 @@
package commands
import (
"errors"
"fmt"
"strings"
"github.com/go-errors/errors"
)
// Service is a service that repository is on (Github, Bitbucket, ...)