[libvirt] [go PATCH 35/37] error: remove GetLastError() function

Daniel P. Berrangé berrange at redhat.com
Mon Jul 16 13:24:21 UTC 2018


The virGetLastError() function fetches the last reported error from a
thread local variable. Goroutines may be arbitrarily switched between OS
threads between the libvirt API call and the virGetLastError()
call. Thus this API is impossible to use safely and must be removed. All
the Go APIs return an error object directly so nothing should need the
GetLastError() binding anyway.

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 api_test.go |  1 +
 error.go    | 20 --------------------
 2 files changed, 1 insertion(+), 20 deletions(-)

diff --git a/api_test.go b/api_test.go
index a16a1eb..564bdd4 100644
--- a/api_test.go
+++ b/api_test.go
@@ -68,6 +68,7 @@ var (
 		/* Only needed at C level */
 		"virCopyLastError",
 		"virFreeError",
+		"virGetLastError",
 		"virGetLastErrorMessage",
 		"virGetLastErrorCode",
 		"virGetLastErrorDomain",
diff --git a/error.go b/error.go
index b8e2900..37fefc1 100644
--- a/error.go
+++ b/error.go
@@ -594,26 +594,6 @@ func makeError(err *C.virError) Error {
 	return ret
 }
 
-func GetLastError() Error {
-	err := C.virGetLastError()
-	if err == nil {
-		return Error{
-			Code:    ERR_OK,
-			Domain:  FROM_NONE,
-			Message: "Missing error",
-			Level:   ERR_NONE,
-		}
-	}
-	virErr := Error{
-		Code:    ErrorNumber(err.code),
-		Domain:  ErrorDomain(err.domain),
-		Message: C.GoString(err.message),
-		Level:   ErrorLevel(err.level),
-	}
-	C.virResetError(err)
-	return virErr
-}
-
 func GetNotImplementedError(apiname string) Error {
 	return Error{
 		Code:    ERR_NO_SUPPORT,
-- 
2.17.1




More information about the libvir-list mailing list