From dbbafd54a5c503aad754df079a8defeb759b917c Mon Sep 17 00:00:00 2001
From: Abubakr-Sadik Nii Nai Davis <dwa2pac@gmail.com>
Date: Wed, 5 Jul 2017 12:56:01 +0000
Subject: [PATCH] Do not exit on command exit, print error message to stderr
 and continue.

---
 check/check.go | 19 ++++++++++++-------
 cmd/common.go  | 12 ++++++++++--
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/check/check.go b/check/check.go
index c912d98..0e16a42 100644
--- a/check/check.go
+++ b/check/check.go
@@ -63,7 +63,7 @@ type Check struct {
 // Run executes the audit commands specified in a check and outputs
 // the results.
 func (c *Check) Run() {
-	var out, serr bytes.Buffer
+	var out bytes.Buffer
 
 	// Check if command exists or exit with WARN.
 	for _, cmd := range c.Commands {
@@ -88,7 +88,7 @@ func (c *Check) Run() {
 	cs := c.Commands
 
 	// Initialize command pipeline
-	cs[0].Stderr = &serr
+	cs[0].Stderr = os.Stderr
 	cs[n-1].Stdout = &out
 	i := 1
 
@@ -96,25 +96,30 @@ func (c *Check) Run() {
 	for i < n {
 		cs[i-1].Stdout, err = cs[i].StdinPipe()
 		if err != nil {
-			fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Path, err)
-			os.Exit(1)
+			fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Args, err)
 		}
 
-		cs[i].Stderr = &serr
+		cs[i].Stderr = os.Stderr
 		i++
 	}
 
 	// Start command pipeline
 	i = 0
 	for i < n {
-		cs[i].Start()
+		err := cs[i].Start()
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Args, err)
+		}
 		i++
 	}
 
 	// Complete command pipeline
 	i = 0
 	for i < n {
-		cs[i].Wait()
+		err := cs[i].Wait()
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Args, err)
+		}
 
 		if i < n-1 {
 			cs[i].Stdout.(io.Closer).Close()
diff --git a/cmd/common.go b/cmd/common.go
index a2f51a5..93a0c7e 100644
--- a/cmd/common.go
+++ b/cmd/common.go
@@ -238,7 +238,11 @@ func verifyBin(binPath []string) []string {
 
 	// Run ps command
 	cmd := exec.Command("ps", "-C", binList, "-o", "cmd", "--no-headers")
-	out, _ := cmd.Output()
+	cmd.Stderr = os.Stderr
+	out, err := cmd.Output()
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "%s: %s\n", cmd.Args, err)
+	}
 
 	// Actual verification
 	for _, b := range binPath {
@@ -266,7 +270,11 @@ func verifyKubeVersion(binPath []string) []string {
 
 		// Check version
 		cmd := exec.Command(b, "--version")
-		out, _ := cmd.Output()
+		cmd.Stderr = os.Stderr
+		out, err := cmd.Output()
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "%s: %s\n", cmd.Args, err)
+		}
 
 		matched := strings.Contains(string(out), kubeVersion)
 		if !matched {
-- 
GitLab