[lxc-devel] [lxd/master] shared: Use custom error type for RunCommand
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Jul 6 20:49:38 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170706/26cbbc55/attachment.bin>
-------------- next part --------------
From 0c1a8baecf6068cdcb5ec9f1147a5ad69fbfa4de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 6 Jul 2017 16:19:08 -0400
Subject: [PATCH] shared: Use custom error type for RunCommand
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #3502
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
shared/util.go | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/shared/util.go b/shared/util.go
index 21648147f..44a33c02a 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -775,10 +775,23 @@ func RemoveDuplicatesFromString(s string, sep string) string {
return s
}
+type RunError struct {
+ msg string
+ Err error
+}
+
+func (e RunError) Error() string {
+ return e.msg
+}
+
func RunCommand(name string, arg ...string) (string, error) {
output, err := exec.Command(name, arg...).CombinedOutput()
if err != nil {
- return string(output), fmt.Errorf("Failed to run: %s %s: %s", name, strings.Join(arg, " "), strings.TrimSpace(string(output)))
+ err := RunError{
+ msg: fmt.Sprintf("Failed to run: %s %s: %s", name, strings.Join(arg, " "), strings.TrimSpace(string(output))),
+ Err: err,
+ }
+ return string(output), err
}
return string(output), nil
More information about the lxc-devel
mailing list