From 31b1bb761f336774a138d93f334ba458a1787427 Mon Sep 17 00:00:00 2001
From: jbhusson <jonah@elixxir.io>
Date: Wed, 9 Mar 2022 21:18:46 -0500
Subject: [PATCH] Logging fixes, check path param before trying to load

---
 client/client_test.go |  2 +-
 cmd/server.go         |  3 +++
 server/serverImpl.go  | 28 ++++++++++++++++------------
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/client/client_test.go b/client/client_test.go
index 3182809..9073f47 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -93,7 +93,7 @@ func TestSignAndTransmit(t *testing.T) {
 			Port:         "11420",
 		}, mapImpl)
 		if err != nil {
-			t.Errorf("Failed to start dummy server")
+			t.Errorf("Failed to start dummy server: %+v", err)
 			errChan <- err
 		} else {
 			doneChan <- true
diff --git a/cmd/server.go b/cmd/server.go
index 04d599b..f4c1bbf 100644
--- a/cmd/server.go
+++ b/cmd/server.go
@@ -90,6 +90,9 @@ var serverCmd = &cobra.Command{
 		}
 
 		err = server.StartServer(params, s)
+		if err != nil {
+			jww.FATAL.Fatalf("Failed to start server: %+v", err)
+		}
 		var stopCh = make(chan bool)
 		select {
 		case <-stopCh:
diff --git a/server/serverImpl.go b/server/serverImpl.go
index f41d3c7..215b1df 100644
--- a/server/serverImpl.go
+++ b/server/serverImpl.go
@@ -52,19 +52,21 @@ func StartServer(params Params, s *storage.Storage) error {
 	}
 
 	// Attempt to load in list of node IDs exempt from duplicate wallet checking
-	if p, err := pathutils.ExpandPath(params.IDListPath); err == nil {
-		idList, err := pathutils.ReadFile(p)
-		if err != nil {
-			return errors.WithMessage(err, "Failed to read ID list path")
-		}
-		r := csv.NewReader(bytes.NewReader(idList))
-		records, err := r.ReadAll()
-		for _, r := range records {
-			nid := r[0]
-			impl.idList[nid] = true
+	if params.IDListPath != "" {
+		if p, err := pathutils.ExpandPath(params.IDListPath); err == nil {
+			idList, err := pathutils.ReadFile(p)
+			if err != nil {
+				return errors.WithMessage(err, "Failed to read ID list path")
+			}
+			r := csv.NewReader(bytes.NewReader(idList))
+			records, err := r.ReadAll()
+			for _, r := range records {
+				nid := r[0]
+				impl.idList[nid] = true
+			}
+		} else {
+			return errors.WithMessage(err, "Failed to expand ID list path")
 		}
-	} else {
-		return errors.WithMessage(err, "Failed to expand ID list path")
 	}
 
 	// Build gin server, link to verify code
@@ -97,7 +99,9 @@ func StartServer(params Params, s *storage.Storage) error {
 		c.JSON(http.StatusAccepted, newCommitment)
 	})
 	impl.comms = r
+
 	// Run with TLS
+	jww.INFO.Print("Starting commitments server...")
 	if params.KeyPath == "" && params.CertPath == "" {
 		jww.WARN.Println("NO TLS CONFIGURED")
 		return r.Run(fmt.Sprintf("0.0.0.0:%s", params.Port))
-- 
GitLab