SEBA-705 better error reporting

Change-Id: Id461c6efe2d0b7ab9c0d1ddb72482d10899b16fe
diff --git a/cmd/cordctl.go b/cmd/cordctl.go
index 19a27c7..55991d5 100644
--- a/cmd/cordctl.go
+++ b/cmd/cordctl.go
@@ -19,6 +19,7 @@
 import (
 	flags "github.com/jessevdk/go-flags"
 	"github.com/opencord/cordctl/commands"
+	corderrors "github.com/opencord/cordctl/error"
 	"os"
 	"path"
 )
@@ -48,9 +49,18 @@
 			if real.Type == flags.ErrHelp {
 				return
 			}
-		} else {
-			panic(err)
 		}
+
+		corderror, ok := err.(corderrors.CordCtlError)
+		if ok {
+			if corderror.ShouldDumpStack() || commands.GlobalOptions.Debug {
+				os.Stderr.WriteString("\n" + corderror.Stack())
+			}
+		}
+
+		// parser.ParseArgs already printed the error message
+		// Any stack trace emitted by panic() here would be of main() and not useful
+		// So just exit and be done with it.
 		os.Exit(1)
 	}
 }