All of lore.kernel.org
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Ronald Rojas <ronladred@gmail.com>, Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <ian.jackson@citrix.com>
Subject: [PATCH v5 02/10] golang/xenlight: Add error constants and standard handling
Date: Wed, 5 Apr 2017 17:05:46 +0100	[thread overview]
Message-ID: <1491408354-9643-3-git-send-email-george.dunlap@citrix.com> (raw)
In-Reply-To: <1491408354-9643-1-git-send-email-george.dunlap@citrix.com>

From: Ronald Rojas <ronladred@gmail.com>

Create error type Errorxl for throwing proper xenlight
errors.

Update Ctx functions to throw Errorxl errors.

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
Reviewed-by:  George Dunlap <george.dunlap@citrix.com>
---
CC: Ian Jackson <ian.jackson@citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>

 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
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-04-05 16:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-05 16:05 [PATCH v5 00/10] tools: Implement basic golang bindings for libxl George Dunlap
2017-04-05 16:05 ` [PATCH v5 01/10] golang/xenlight: Create stub package George Dunlap
2017-04-05 16:05 ` George Dunlap [this message]
2017-04-05 16:05 ` [PATCH v5 03/10] golang/xenlight: Add host-related functionality George Dunlap
2017-04-05 16:05 ` [PATCH v5 04/10] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause George Dunlap
2017-04-05 16:05 ` [PATCH v5 05/10] golang/xenlight: Implement libxl_bitmap and helper operations George Dunlap
2017-04-05 16:05 ` [PATCH v5 06/10] golang/xenlight: Implement libxl_scheduler enumeration George Dunlap
2017-04-05 16:05 ` [PATCH v5 07/10] golang/xenlight: Implement Domain operations George Dunlap
2017-04-05 16:05 ` [PATCH v5 08/10] golang/xenlight: Implement Vcpuinfo and ListVcpu George Dunlap
2017-04-05 16:05 ` [PATCH v5 09/10] golang/xenlight: Implement get console path operations George Dunlap
2017-04-05 16:05 ` [PATCH v5 10/10] golang/xenlight: Implement cpupool operations George Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1491408354-9643-3-git-send-email-george.dunlap@citrix.com \
    --to=george.dunlap@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=ronladred@gmail.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.