[lxc-devel] [go-lxc/v2] Make errors constants

caglar10ur on Github lxc-bot at linuxcontainers.org
Sat Apr 27 22:31:27 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 399 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190427/d5a5976d/attachment.bin>
-------------- next part --------------
From 97190c1188d39ebd13b4d08e9882aecee232d6d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=2E=C3=87a=C4=9Flar=20Onur?= <caglar at 10ur.org>
Date: Sat, 27 Apr 2019 15:30:15 -0700
Subject: [PATCH] Make errors constants
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

since we don't want users to set them to nil

Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>
---
 error.go | 140 ++++++++++++++++++++++++++-----------------------------
 1 file changed, 65 insertions(+), 75 deletions(-)

diff --git a/error.go b/error.go
index e426935..533cb10 100644
--- a/error.go
+++ b/error.go
@@ -6,82 +6,72 @@
 
 package lxc
 
-var (
-	ErrAddDeviceNodeFailed           = NewError("adding device to container failed")
-	ErrAllocationFailed              = NewError("allocating memory failed")
-	ErrAlreadyDefined                = NewError("container already defined")
-	ErrAlreadyFrozen                 = NewError("container is already frozen")
-	ErrAlreadyRunning                = NewError("container is already running")
-	ErrAttachFailed                  = NewError("attaching to the container failed")
-	ErrAttachInterfaceFailed         = NewError("attaching specified netdev to the container failed")
-	ErrBlkioUsage                    = NewError("BlkioUsage for the container failed")
-	ErrCheckpointFailed              = NewError("checkpoint failed")
-	ErrClearingConfigItemFailed      = NewError("clearing config item for the container failed")
-	ErrClearingCgroupItemFailed      = NewError("clearing cgroup item for the container failed")
-	ErrCloneFailed                   = NewError("cloning the container failed")
-	ErrCloseAllFdsFailed             = NewError("setting close_all_fds flag for container failed")
-	ErrCreateFailed                  = NewError("creating the container failed")
-	ErrCreateSnapshotFailed          = NewError("snapshotting the container failed")
-	ErrDaemonizeFailed               = NewError("setting daemonize flag for container failed")
-	ErrDestroyAllSnapshotsFailed     = NewError("destroying all snapshots failed")
-	ErrDestroyFailed                 = NewError("destroying the container failed")
-	ErrDestroySnapshotFailed         = NewError("destroying the snapshot failed")
-	ErrDestroyWithAllSnapshotsFailed = NewError("destroying the container with all snapshots failed")
-	ErrDetachInterfaceFailed         = NewError("detaching specified netdev to the container failed")
-	ErrExecuteFailed                 = NewError("executing the command in a temporary container failed")
-	ErrFreezeFailed                  = NewError("freezing the container failed")
-	ErrInsufficientNumberOfArguments = NewError("insufficient number of arguments were supplied")
-	ErrInterfaces                    = NewError("getting interface names for the container failed")
-	ErrIPAddresses                   = NewError("getting IP addresses of the container failed")
-	ErrIPAddress                     = NewError("getting IP address on the interface of the container failed")
-	ErrIPv4Addresses                 = NewError("getting IPv4 addresses of the container failed")
-	ErrIPv6Addresses                 = NewError("getting IPv6 addresses of the container failed")
-	ErrKMemLimit                     = NewError("your kernel does not support cgroup kernel memory controller")
-	ErrLoadConfigFailed              = NewError("loading config file for the container failed")
-	ErrMemLimit                      = NewError("your kernel does not support cgroup memory controller")
-	ErrMemorySwapLimit               = NewError("your kernel does not support cgroup swap controller")
-	ErrMethodNotAllowed              = NewError("the requested method is not currently supported with unprivileged containers")
-	ErrNewFailed                     = NewError("allocating the container failed")
-	ErrNoSnapshot                    = NewError("container has no snapshot")
-	ErrNotDefined                    = NewError("container is not defined")
-	ErrNotFrozen                     = NewError("container is not frozen")
-	ErrNotRunning                    = NewError("container is not running")
-	ErrNotSupported                  = NewError("method is not supported by this LXC version")
-	ErrRebootFailed                  = NewError("rebooting the container failed")
-	ErrRemoveDeviceNodeFailed        = NewError("removing device from container failed")
-	ErrRenameFailed                  = NewError("renaming the container failed")
-	ErrRestoreFailed                 = NewError("restore failed")
-	ErrRestoreSnapshotFailed         = NewError("restoring the container failed")
-	ErrSaveConfigFailed              = NewError("saving config file for the container failed")
-	ErrSettingCgroupItemFailed       = NewError("setting cgroup item for the container failed")
-	ErrSettingConfigItemFailed       = NewError("setting config item for the container failed")
-	ErrSettingConfigPathFailed       = NewError("setting config file for the container failed")
-	ErrSettingKMemoryLimitFailed     = NewError("setting kernel memory limit for the container failed")
-	ErrSettingMemoryLimitFailed      = NewError("setting memory limit for the container failed")
-	ErrSettingMemorySwapLimitFailed  = NewError("setting memory+swap limit for the container failed")
-	ErrSettingSoftMemoryLimitFailed  = NewError("setting soft memory limit for the container failed")
-	ErrShutdownFailed                = NewError("shutting down the container failed")
-	ErrSoftMemLimit                  = NewError("your kernel does not support cgroup memory controller")
-	ErrStartFailed                   = NewError("starting the container failed")
-	ErrStopFailed                    = NewError("stopping the container failed")
-	ErrTemplateNotAllowed            = NewError("unprivileged users only allowed to use \"download\" template")
-	ErrUnfreezeFailed                = NewError("unfreezing the container failed")
-	ErrUnknownBackendStore           = NewError("unknown backend type")
-	ErrReleaseFailed                 = NewError("releasing the container failed")
+const (
+	ErrAddDeviceNodeFailed           = lxcError("adding device to container failed")
+	ErrAllocationFailed              = lxcError("allocating memory failed")
+	ErrAlreadyDefined                = lxcError("container already defined")
+	ErrAlreadyFrozen                 = lxcError("container is already frozen")
+	ErrAlreadyRunning                = lxcError("container is already running")
+	ErrAttachFailed                  = lxcError("attaching to the container failed")
+	ErrAttachInterfaceFailed         = lxcError("attaching specified netdev to the container failed")
+	ErrBlkioUsage                    = lxcError("BlkioUsage for the container failed")
+	ErrCheckpointFailed              = lxcError("checkpoint failed")
+	ErrClearingConfigItemFailed      = lxcError("clearing config item for the container failed")
+	ErrClearingCgroupItemFailed      = lxcError("clearing cgroup item for the container failed")
+	ErrCloneFailed                   = lxcError("cloning the container failed")
+	ErrCloseAllFdsFailed             = lxcError("setting close_all_fds flag for container failed")
+	ErrCreateFailed                  = lxcError("creating the container failed")
+	ErrCreateSnapshotFailed          = lxcError("snapshotting the container failed")
+	ErrDaemonizeFailed               = lxcError("setting daemonize flag for container failed")
+	ErrDestroyAllSnapshotsFailed     = lxcError("destroying all snapshots failed")
+	ErrDestroyFailed                 = lxcError("destroying the container failed")
+	ErrDestroySnapshotFailed         = lxcError("destroying the snapshot failed")
+	ErrDestroyWithAllSnapshotsFailed = lxcError("destroying the container with all snapshots failed")
+	ErrDetachInterfaceFailed         = lxcError("detaching specified netdev to the container failed")
+	ErrExecuteFailed                 = lxcError("executing the command in a temporary container failed")
+	ErrFreezeFailed                  = lxcError("freezing the container failed")
+	ErrInsufficientNumberOfArguments = lxcError("insufficient number of arguments were supplied")
+	ErrInterfaces                    = lxcError("getting interface names for the container failed")
+	ErrIPAddresses                   = lxcError("getting IP addresses of the container failed")
+	ErrIPAddress                     = lxcError("getting IP address on the interface of the container failed")
+	ErrIPv4Addresses                 = lxcError("getting IPv4 addresses of the container failed")
+	ErrIPv6Addresses                 = lxcError("getting IPv6 addresses of the container failed")
+	ErrKMemLimit                     = lxcError("your kernel does not support cgroup kernel memory controller")
+	ErrLoadConfigFailed              = lxcError("loading config file for the container failed")
+	ErrMemLimit                      = lxcError("your kernel does not support cgroup memory controller")
+	ErrMemorySwapLimit               = lxcError("your kernel does not support cgroup swap controller")
+	ErrMethodNotAllowed              = lxcError("the requested method is not currently supported with unprivileged containers")
+	ErrNewFailed                     = lxcError("allocating the container failed")
+	ErrNoSnapshot                    = lxcError("container has no snapshot")
+	ErrNotDefined                    = lxcError("container is not defined")
+	ErrNotFrozen                     = lxcError("container is not frozen")
+	ErrNotRunning                    = lxcError("container is not running")
+	ErrNotSupported                  = lxcError("method is not supported by this LXC version")
+	ErrRebootFailed                  = lxcError("rebooting the container failed")
+	ErrRemoveDeviceNodeFailed        = lxcError("removing device from container failed")
+	ErrRenameFailed                  = lxcError("renaming the container failed")
+	ErrRestoreFailed                 = lxcError("restore failed")
+	ErrRestoreSnapshotFailed         = lxcError("restoring the container failed")
+	ErrSaveConfigFailed              = lxcError("saving config file for the container failed")
+	ErrSettingCgroupItemFailed       = lxcError("setting cgroup item for the container failed")
+	ErrSettingConfigItemFailed       = lxcError("setting config item for the container failed")
+	ErrSettingConfigPathFailed       = lxcError("setting config file for the container failed")
+	ErrSettingKMemoryLimitFailed     = lxcError("setting kernel memory limit for the container failed")
+	ErrSettingMemoryLimitFailed      = lxcError("setting memory limit for the container failed")
+	ErrSettingMemorySwapLimitFailed  = lxcError("setting memory+swap limit for the container failed")
+	ErrSettingSoftMemoryLimitFailed  = lxcError("setting soft memory limit for the container failed")
+	ErrShutdownFailed                = lxcError("shutting down the container failed")
+	ErrSoftMemLimit                  = lxcError("your kernel does not support cgroup memory controller")
+	ErrStartFailed                   = lxcError("starting the container failed")
+	ErrStopFailed                    = lxcError("stopping the container failed")
+	ErrTemplateNotAllowed            = lxcError("unprivileged users only allowed to use \"download\" template")
+	ErrUnfreezeFailed                = lxcError("unfreezing the container failed")
+	ErrUnknownBackendStore           = lxcError("unknown backend type")
+	ErrReleaseFailed                 = lxcError("releasing the container failed")
 )
 
-// Error represents a basic error that implies the error interface.
-type Error struct {
-	Message string
-}
-
-// NewError creates a new error with the given msg argument.
-func NewError(msg string) error {
-	return &Error{
-		Message: msg,
-	}
-}
+type lxcError string
 
-func (e *Error) Error() string {
-	return e.Message
+func (e lxcError) Error() string {
+	return string(e)
 }


More information about the lxc-devel mailing list