Catch nil error instances
Unfortunately libgit2 sometimes returns an error without setting an error message. Provide an alternative message instead of trying to dereference nil.
This commit is contained in:
parent
4e0a28b064
commit
d824ea415d
4
git.go
4
git.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"strings"
|
"strings"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -107,6 +108,9 @@ func (e GitError) Error() string{
|
||||||
|
|
||||||
func LastError() error {
|
func LastError() error {
|
||||||
err := C.giterr_last()
|
err := C.giterr_last()
|
||||||
|
if err == nil {
|
||||||
|
return &GitError{"No message", 0}
|
||||||
|
}
|
||||||
return &GitError{C.GoString(err.message), int(err.klass)}
|
return &GitError{C.GoString(err.message), int(err.klass)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue