From b57339b6f42dd1997d8aef3580dfb7411a56a99f Mon Sep 17 00:00:00 2001 From: George Dunlap Date: Thu, 29 Dec 2016 19:36:15 +0000 Subject: [PATCH 2/7] tools/golang: Add error constants and standard handling You're going to change this so I won't bother writing a description -- write here though a description of what the patch does and a brief account of why. --- tools/golang/xenlight/xenlight.go | 90 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index b162abb..677e5a5 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -32,6 +32,96 @@ import ( ) /* + * Errors + */ +const ( + ErrorNonspecific = int(C.ERROR_NONSPECIFIC) + ErrorVersion = int(C.ERROR_VERSION) + ErrorFail = int(C.ERROR_FAIL) + ErrorNi = int(C.ERROR_NI) + ErrorNomem = int(C.ERROR_NOMEM) + ErrorInval = int(C.ERROR_INVAL) + ErrorBadfail = int(C.ERROR_BADFAIL) + ErrorGuestTimedout = int(C.ERROR_GUEST_TIMEDOUT) + ErrorTimedout = int(C.ERROR_TIMEDOUT) + ErrorNoparavirt = int(C.ERROR_NOPARAVIRT) + ErrorNotReady = int(C.ERROR_NOT_READY) + ErrorOseventRegFail = int(C.ERROR_OSEVENT_REG_FAIL) + ErrorBufferfull = int(C.ERROR_BUFFERFULL) + ErrorUnknownChild = int(C.ERROR_UNKNOWN_CHILD) + ErrorLockFail = int(C.ERROR_LOCK_FAIL) + ErrorJsonConfigEmpty = int(C.ERROR_JSON_CONFIG_EMPTY) + ErrorDeviceExists = int(C.ERROR_DEVICE_EXISTS) + ErrorCheckpointDevopsDoesNotMatch = int(C.ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH) + ErrorCheckpointDeviceNotSupported = int(C.ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED) + ErrorVnumaConfigInvalid = int(C.ERROR_VNUMA_CONFIG_INVALID) + ErrorDomainNotfound = int(C.ERROR_DOMAIN_NOTFOUND) + ErrorAborted = int(C.ERROR_ABORTED) + ErrorNotfound = int(C.ERROR_NOTFOUND) + ErrorDomainDestroyed = int(C.ERROR_DOMAIN_DESTROYED) + ErrorFeatureRemoved = int(C.ERROR_FEATURE_REMOVED) +) + +func createError(method string, cerrNum C.int) (err error) { + method += " %s" + errNum := int(cerrNum) + switch errNum { + case ErrorNonspecific: + err = fmt.Errorf(method, "ERROR_NONSPECIFIC") + case ErrorVersion: + err = fmt.Errorf(method, "ERROR_VERSION") + case ErrorFail: + err = fmt.Errorf(method, "ERROR_FAIL") + case ErrorNi: + err = fmt.Errorf(method, "ERROR_NI") + case ErrorNomem: + err = fmt.Errorf(method, "ERROR_NOMEM") + case ErrorInval: + err = fmt.Errorf(method, "ERROR_INVAL") + case ErrorBadfail: + err = fmt.Errorf(method, "ERROR_BADFAIL") + case ErrorGuestTimedout: + err = fmt.Errorf(method, "ERROR_GUEST_TIMEDOUT") + case ErrorNoparavirt: + err = fmt.Errorf(method, "ERROR_NOPARAVIRT") + case ErrorNotReady: + err = fmt.Errorf(method, "ERROR_NOT_READY") + case ErrorOseventRegFail: + err = fmt.Errorf(method, "ERROR_OSEVENT_REG_FAIL") + case ErrorBufferfull: + err = fmt.Errorf(method, "ERROR_BUFFERFULL") + case ErrorUnknownChild: + err = fmt.Errorf(method, "ERROR_UNKNOWN_CHILD") + case ErrorLockFail: + err = fmt.Errorf(method, "ERROR_LOCK_FAIL") + case ErrorJsonConfigEmpty: + err = fmt.Errorf(method, "ERROR_JSON_CONFIG_EMPTY") + case ErrorDeviceExists: + err = fmt.Errorf(method, "ERROR_DEVICE_EXISTS") + case ErrorCheckpointDevopsDoesNotMatch: + err = fmt.Errorf(method, "ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH") + case ErrorCheckpointDeviceNotSupported: + err = fmt.Errorf(method, "ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED") + case ErrorVnumaConfigInvalid: + err = fmt.Errorf(method, "ERROR_VNUMA_CONFIG_INVALID") + case ErrorDomainNotfound: + err = fmt.Errorf(method, "ERROR_DOMAIN_NOTFOUND") + case ErrorAborted: + err = fmt.Errorf(method, "ERROR_ABORTED") + case ErrorNotfound: + err = fmt.Errorf(method, "ERROR_NOTFOUND") + case ErrorDomainDestroyed: + err = fmt.Errorf(method, "ERROR_DOMAIN_DESTROYED") + case ErrorFeatureRemoved: + err = fmt.Errorf(method, "ERROR_FEATURE_REMOVED") + default: + err = fmt.Errorf(method, "error not found") + } + return + +} + +/* * Types: Builtins */ type Context struct { -- 2.1.4