[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] golang/xenlight: Add error constants and standard handling



commit 73be0fd3902cc1814bb720fd1330182332a09592
Author:     Ronald Rojas <ronladred@xxxxxxxxx>
AuthorDate: Wed Apr 5 17:05:46 2017 +0100
Commit:     George Dunlap <george.dunlap@xxxxxxxxxx>
CommitDate: Thu Apr 6 15:34:00 2017 +0100

    golang/xenlight: Add error constants and standard handling
    
    Create error type Errorxl for throwing proper xenlight
    errors.
    
    Update Ctx functions to throw Errorxl errors.
    
    Signed-off-by: Ronald Rojas <ronladred@xxxxxxxxx>
    Reviewed-by:  George Dunlap <george.dunlap@xxxxxxxxxx>
    Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxx>
---
 tools/golang/xenlight/xenlight.go | 78 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 76 insertions(+), 2 deletions(-)

diff --git a/tools/golang/xenlight/xenlight.go 
b/tools/golang/xenlight/xenlight.go
index 7be180c..de24ffd 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -37,8 +37,82 @@ import (
 )
 
 /*
+ * Errors
+ */
+
+type Error int
+
+const (
+       ErrorNonspecific                  = Error(-C.ERROR_NONSPECIFIC)
+       ErrorVersion                      = Error(-C.ERROR_VERSION)
+       ErrorFail                         = Error(-C.ERROR_FAIL)
+       ErrorNi                           = Error(-C.ERROR_NI)
+       ErrorNomem                        = Error(-C.ERROR_NOMEM)
+       ErrorInval                        = Error(-C.ERROR_INVAL)
+       ErrorBadfail                      = Error(-C.ERROR_BADFAIL)
+       ErrorGuestTimedout                = Error(-C.ERROR_GUEST_TIMEDOUT)
+       ErrorTimedout                     = Error(-C.ERROR_TIMEDOUT)
+       ErrorNoparavirt                   = Error(-C.ERROR_NOPARAVIRT)
+       ErrorNotReady                     = Error(-C.ERROR_NOT_READY)
+       ErrorOseventRegFail               = Error(-C.ERROR_OSEVENT_REG_FAIL)
+       ErrorBufferfull                   = Error(-C.ERROR_BUFFERFULL)
+       ErrorUnknownChild                 = Error(-C.ERROR_UNKNOWN_CHILD)
+       ErrorLockFail                     = Error(-C.ERROR_LOCK_FAIL)
+       ErrorJsonConfigEmpty              = Error(-C.ERROR_JSON_CONFIG_EMPTY)
+       ErrorDeviceExists                 = Error(-C.ERROR_DEVICE_EXISTS)
+       ErrorCheckpointDevopsDoesNotMatch = 
Error(-C.ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH)
+       ErrorCheckpointDeviceNotSupported = 
Error(-C.ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED)
+       ErrorVnumaConfigInvalid           = Error(-C.ERROR_VNUMA_CONFIG_INVALID)
+       ErrorDomainNotfound               = Error(-C.ERROR_DOMAIN_NOTFOUND)
+       ErrorAborted                      = Error(-C.ERROR_ABORTED)
+       ErrorNotfound                     = Error(-C.ERROR_NOTFOUND)
+       ErrorDomainDestroyed              = Error(-C.ERROR_DOMAIN_DESTROYED)
+       ErrorFeatureRemoved               = Error(-C.ERROR_FEATURE_REMOVED)
+)
+
+var errors = [...]string{
+       ErrorNonspecific:                  "Non-specific error",
+       ErrorVersion:                      "Wrong version",
+       ErrorFail:                         "Failed",
+       ErrorNi:                           "Not Implemented",
+       ErrorNomem:                        "No memory",
+       ErrorInval:                        "Invalid argument",
+       ErrorBadfail:                      "Bad Fail",
+       ErrorGuestTimedout:                "Guest timed out",
+       ErrorTimedout:                     "Timed out",
+       ErrorNoparavirt:                   "No Paravirtualization",
+       ErrorNotReady:                     "Not ready",
+       ErrorOseventRegFail:               "OS event registration failed",
+       ErrorBufferfull:                   "Buffer full",
+       ErrorUnknownChild:                 "Unknown child",
+       ErrorLockFail:                     "Lock failed",
+       ErrorJsonConfigEmpty:              "JSON config empty",
+       ErrorDeviceExists:                 "Device exists",
+       ErrorCheckpointDevopsDoesNotMatch: "Checkpoint devops does not match",
+       ErrorCheckpointDeviceNotSupported: "Checkpoint device not supported",
+       ErrorVnumaConfigInvalid:           "VNUMA config invalid",
+       ErrorDomainNotfound:               "Domain not found",
+       ErrorAborted:                      "Aborted",
+       ErrorNotfound:                     "Not found",
+       ErrorDomainDestroyed:              "Domain destroyed",
+       ErrorFeatureRemoved:               "Feature removed",
+}
+
+func (e Error) Error() string {
+       if 0 < int(e) && int(e) < len(errors) {
+               s := errors[e]
+               if s != "" {
+                       return s
+               }
+       }
+       return fmt.Sprintf("libxl error: %d", -e)
+
+}
+
+/*
  * Types: Builtins
  */
+
 type Context struct {
        ctx    *C.libxl_ctx
        logger *C.xentoollog_logger_stdiostream
@@ -68,7 +142,7 @@ func (Ctx *Context) Open() (err error) {
                0, unsafe.Pointer(Ctx.logger))
 
        if ret != 0 {
-               err = fmt.Errorf("Error: %d", -ret)
+               err = Error(-ret)
        }
        return
 }
@@ -78,7 +152,7 @@ func (Ctx *Context) Close() (err error) {
        Ctx.ctx = nil
 
        if ret != 0 {
-               err = fmt.Errorf("Error: %d", -ret)
+               err = Error(-ret)
        }
        C.xtl_logger_destroy(unsafe.Pointer(Ctx.logger))
        return
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.