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:
Carlos Martín Nieto 2013-05-21 11:51:31 +02:00
parent 4e0a28b064
commit d824ea415d
1 changed files with 4 additions and 0 deletions

4
git.go
View File

@ -10,6 +10,7 @@ import (
"bytes"
"unsafe"
"strings"
"fmt"
)
const (
@ -107,6 +108,9 @@ func (e GitError) Error() string{
func LastError() error {
err := C.giterr_last()
if err == nil {
return &GitError{"No message", 0}
}
return &GitError{C.GoString(err.message), int(err.klass)}
}