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

[Xen-changelog] [xen staging] golang/xenlight: Errors are negative



commit 8ea9f5c56c0dfdd8089718fb86541b6025638328
Author:     George Dunlap <george.dunlap@xxxxxxxxxx>
AuthorDate: Thu Dec 26 17:18:14 2019 +0000
Commit:     George Dunlap <george.dunlap@xxxxxxxxxx>
CommitDate: Tue Jan 21 17:48:24 2020 +0000

    golang/xenlight: Errors are negative
    
    Commit 871e51d2d4 changed the sign on the xenlight error types (making
    the values negative, same as the C-generated constants), but failed to
    flip the sign in the Error() string function.  The result is that
    ErrorNonspecific.String() prints "libxl error: 1" rather than the
    human-readable error message.
    
    Get rid of the whole issue by making libxlErrors a map, and mapping
    actual error values to string, falling back to printing the actual
    value of the Error type if it's not present.
    
    Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>
    Reviewed-by: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>
---
 tools/golang/xenlight/xenlight.go | 62 +++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 32 deletions(-)

diff --git a/tools/golang/xenlight/xenlight.go 
b/tools/golang/xenlight/xenlight.go
index 1299981713..aa1e63a61a 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -36,42 +36,40 @@ import (
        "unsafe"
 )
 
-var libxlErrors = [...]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",
+var libxlErrors = map[Error]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(libxlErrors) {
-               s := libxlErrors[e]
-               if s != "" {
-                       return s
-               }
+       if s, ok := libxlErrors[e]; ok {
+               return s
        }
-       return fmt.Sprintf("libxl error: %d", -e)
+
+       return fmt.Sprintf("libxl error: %d", e)
 }
 
 // Context represents a libxl_ctx.
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
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®.