Commit bff7f37

Richard Luby <richluby@gmail.com>
2016-11-01 06:53:53
improved logging messages
1 parent a69d4a7
client.go
@@ -65,12 +65,12 @@ func initUserSession() {
 		}
 		// select a command from the list of available commands
 		if command, err = selectCommand(strings.TrimSpace(args[0])); err != nil {
-			log.Printf("Error while selecting command: %+v", err)
+			log.Printf("Error while parsing command: %+v", err)
 			continue
 		}
 		// execute the command and check for any errors that may have occurred
 		if err = command.Run(args[1:]); err != nil {
-			log.Printf("Error while executing: %+v", err)
+			log.Printf("Error while executing command: %+v", err)
 		}
 	}
 }
command.go
@@ -149,7 +149,7 @@ func executeTest(args []string) error {
 	}
 	recordArray, err = getRecordFromServer(client, clientConfig, questions)
 	if err != nil {
-		return fmt.Errorf("Error while request from server: %+v", err)
+		return fmt.Errorf("Error while requesting test from server: %+v", err)
 	}
 	runTest(recordArray)
 	return postRecordsToServer(client, &recordArray)
server.go
@@ -63,7 +63,7 @@ func loadServerConfiguration(cfgFile string) SERVER_CONFIG {
 		contents = string(buffer)
 	}
 	if _, err := toml.Decode(contents, &config); err != nil {
-		log.Fatalf("Could not parse configuration: %+v\n", err.Error())
+		log.Fatalf("Could not parse configuration file: %+v\n", err.Error())
 		os.Exit(EXIT_CODE.BAD_CONFIG)
 	}
 	return config
serverHandlers.go
@@ -42,6 +42,7 @@ func writeTestFile(username string, data []byte) error {
 	for fileNeedsWrite := true; fileNeedsWrite; {
 		if err = ioutil.WriteFile(filepath.Join(resultsFilePath, id), data, 0400); err != nil {
 			id = fmt.Sprint(rand.Intn(99999))
+			continue
 		}
 		fileNeedsWrite = false
 	}
@@ -58,18 +59,19 @@ func handlePostingTest(writer http.ResponseWriter, request *http.Request) error
 	data, err := ioutil.ReadAll(request.Body)
 	if err != nil {
 		http.Error(writer, "Could not read the test record.", http.StatusBadRequest)
-		return fmt.Errorf("Error for user %s: %+v", username, err)
+		return fmt.Errorf("Error for user %s while reading test: %+v", username, err)
 	}
 	// check to make sure properly formatted client response
 	err = json.Unmarshal(data, &clientResponseRecord)
 	if err != nil {
 		http.Error(writer, "Could not parse the test record.", http.StatusBadRequest)
-		return fmt.Errorf("Error for user %s: %+v", username, err)
+		return fmt.Errorf("Error for user %s while parsing test: %+v", username, err)
 	}
 	log.Printf("Received test from user: %s at %s\tvia %s", username, request.RemoteAddr, request.UserAgent())
 	fmt.Fprint(writer, "Test received successfully.")
 	if err = writeTestFile(username, data); err != nil {
 		http.Error(writer, "Could not save the test record.", http.StatusInternalServerError)
+		return fmt.Errorf("Error for user %s while writing test: %+v", username, err)
 	}
 	return err
 }