diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-02-11 21:30:27 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-02-11 22:39:17 +1100 |
commit | cfe3605e6b29e23db8dca9eedecc58cb13341587 (patch) | |
tree | cff98f9663f184e0979a65135dfd6ab7078744a3 /pkg/commands/os.go | |
parent | 3a607061a2303d9f45d308de652fbebe7300b43c (diff) |
use go-errors package to display stacktrace of errors that cause panics
Diffstat (limited to 'pkg/commands/os.go')
-rw-r--r-- | pkg/commands/os.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go index ffc0516ad..0bd9bf34a 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -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) } |